473,698 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

image resize

123 New Member
i have an image which width is 213 and height is 200 when
i echo the image and i resize it
echo "<img src='company/$present' width='70' height='68'/>";
the image was not as clear as when it was 213 * 200.how can i
make the image clear after i have resize it to 70 * 200.
Jan 23 '09 #1
22 4967
Atli
5,058 Recognized Expert Expert
Hi.

When you resize it as you do, with the <img> height and width attributes, you are essentially leaving it up to the browser to resize it.
Predictably, Internet Explorer does a horrible job at this, while the other major browsers do a pretty good job resizing them.

If you want to ensure that the image is scaled smoothly, you can have PHP resize the image. The GD extension offers the imagecopyresamp led function, which does an excellent job resizing images. (See the documentation for examples on how to use it)

Note that image processing is a very resource intensive task, so if you frequently display you images resized, you should save the resized image to the server's file-system and serve it from there, rather then resize it for every request.
Jan 23 '09 #2
simon2x1
123 New Member
what if i want to echo the image from my database, which
will involve vaious image how can i then resize it and
also keep the resize image smooth like the original.i
will appreciate it if the answer that will be given to me will
be edited on my code

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $query = "SELECT * FROM photo";
  3. $result = mysql_query ($query) or die('query error');
  4. $count = 0;
  5. while ($line = mysql_fetch_array($result, MYSQL_ASSOC)){
  6. $image = $line[picname];
  7. echo "<img src='company/$image'/> ";
  8. $count++;
  9. }
  10.  
Jan 26 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
if you want to echo the image from DB (that is, you have the image itself stored there (as binary data)) you need a script of its own that fetches the image, applies any changes you want (e.g. resizing) and gives out the result.
Jan 26 '09 #4
tharden3
916 Contributor
This article about Uploading files into a MySQL database using PHP
might help you. It discusses a great way to handle image files, although it might not directly answer your "resizing" question. Just throwing it out there as a reference.

Thanks Atli ;)
Jan 26 '09 #5
Markus
6,050 Recognized Expert Expert
Resizing images 'on the fly' (whenever you pull them from a database, etc) will eat into your resources like a fat kid into some delicious cake. When a photo is uploaded, use the GD extension that Atli linked to, and then save a seperate copy of the resized image. That way, you're saving resources, but sacrificing a small amount of HDD space.
Jan 26 '09 #6
simon2x1
123 New Member
i have a problem with the following code below, the image is not showing
the image is display as if there is a missing link, i have check the code
and i see not thing wrong with it and aslo i have enable the GD Library on
my wamp server

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //my Image
  3. $imgSrc = '36.jpg'; 
  4. list($width, $height) = getimagesize($imgSrc); 
  5. //saving the image into memory (for manipulation with GD Library)
  6. $myImage = imagecreatefromjpeg($imgSrc); 
  7. if($width > $height) $biggestSide = $width; 
  8. else $biggestSide = $height; 
  9. $cropPercent = .5; 
  10. $cropWidth   = $biggestSide*$cropPercent; 
  11. $cropHeight  = $biggestSide*$cropPercent; 
  12. $c1 = array("x"=>($width-$cropWidth)/2, "y"=>($height-$cropHeight)/2);
  13. $thumbSize = 60; 
  14. $thumb = imagecreatetruecolor($thumbSize, $thumbSize); 
  15. imagecopyresampled($thumb, $myImage, 0, 0, $c1['x'], $c1['y'], $thumbSize, $thumbSize, $cropWidth, $cropHeight); 
  16. $lineWidth = 1;
  17. $margin    = 0;  
  18. $green    = imagecolorallocate($thumb, 193, 252, 182);
  19.  
  20. for($i=0; $i<2; $i++){
  21. imagefilledrectangle($thumb, $margin, $margin, $margin+$lineWidth, $thumbSize-$margin, $green); 
  22. imagefilledrectangle($thumb, $thumbSize-$margin-$lineWidth, $margin, $thumbSize-$margin, $thumbSize-$margin, $green);
  23. imagefilledrectangle($thumb, $margin, $margin, $thumbSize-$margin-$lineWidth, $margin+$lineWidth, $green); 
  24. imagefilledrectangle($thumb, $margin, $thumbSize-$margin-$lineWidth, $thumbSize-$margin-$lineWidth, $thumbSize-$margin,$green);
  25. $margin+=4; 
  26.     header('Content-type: image/jpeg');
  27.     imagejpeg($thumb);
  28.     imagedestroy($thumb);
  29.  
  30. ?>
Feb 7 '09 #7
TheServant
1,168 Recognized Expert Top Contributor
Line 7, 8 should have {curly brackets}:
Expand|Select|Wrap|Line Numbers
  1. if($width > $height) {$biggestSide = $width;}
  2. else {$biggestSide = $height;}
Other than that I can't see anything big... Will look again later if noone has replied.
Feb 8 '09 #8
Markus
6,050 Recognized Expert Expert
@TheServant
Not true in this case; because the conditional statement only has one statement within it, curly brackets can be omitted.

Expand|Select|Wrap|Line Numbers
  1. // will work
  2. if ( $a === $b )
  3.  echo "hi";
  4. else
  5.  echo "yo";
  6.  
  7. // won't work
  8. if ( $a === $b )
  9.  echo "hello ";
  10.  echo "world";
  11. else
  12.  echo "hi";
  13.  
Feb 8 '09 #9
TheServant
1,168 Recognized Expert Top Contributor
Interesting. I had a feeling that was the case, but wasn't 100% sure. Anyway, I use them all the time for consistency. Thanks for the tip. Suggestion withdrawn.
Feb 9 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

8
4813
by: Chris Dewin | last post by:
Hi. I run a website for my band, and the other guys want an image gallery. I'm thinking it would be nice and easy, if we could just upload a jpg into a dir called "gallery/". When the client clicks the "gallery" link, a cgi script could search the gallery/ dir, and create thumbnails of any jpeg images that don't already have a thumbnail associated with them. The script could then generate a page of clickable thumbnails. A few questions:
2
9446
by: Carl Gilbert | last post by:
Hi I am looking for either a component or technique to allow me to do the following: * Provide a panel with a background image * Resize the image to best fit the panel to maintain aspect ratio * Provide white (or other color) borders at the sides or the top/bottom The last point would be used to allow users to resize the panel to any ratio
15
5341
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the path of the uploaded image, and resize it with the provided dimensions. My function is below. The current function is returning an error when run from the upload function: A generic error occurred in GDI+. Not sure what exactly that means. From what...
1
3776
by: Arjen | last post by:
Hi, I want to resize an image on my server. I tried a lot of samples... but all the time it does resize and saves the images but I can not view the image insize a webbrowser. With an imageviewer (desktop application) I can view the image. I believe there is something wrong with the maximum colors... This is what I have now... Image originalBitmap = Image.FromFile("C:\temp\image.jpg", true);
2
2507
by: Tim Arnold | last post by:
Hi, I'm using the Image module to resize PNG images from 300 to 100dpi for use in HTML pages, but I'm losing some vertical and horizontal lines in the images (usually images of x-y plots). Here's what I do: import Image def imgResize(self,filename): img = Image.open(filename) dpi = img.info.get('dpi') if dpi and 295 < int(dpi) < 305:
2
20899
by: Dominic Vella | last post by:
Hi, I know I seem to have the really complicated questions, but I guess that's why I'm here. This is a little verbose, only because I've been trying to crack this for a week now. Your help would be appreciated. I've been trying numerous ways to resize images, as I want to make store thumbnails, not full images in my database. -----------------------------------------------------------------------------
3
2376
by: danielatdaveschool | last post by:
Hi, noob here Im using mod_python and apache2 using psp for output of page, i open a file and resize it with the following code <% import Image, util fields = util.FieldStorage(req) filename = fields.getlist('src')
8
9418
by: infoseekar | last post by:
Image Resize & Rotation Hi I have 2 scripts, one for Image rotation and other image resize and they both are working. Image resize scripts load the picture and resize it and Image rotation rotate the image by 90 deg. They are two differennt files i.e. resize.php and rotate.php. What I want to do is to combine both rotate.php & resize.php files, so when the script resized the image than it will call rotate script to rotate the...
14
3721
anfetienne
by: anfetienne | last post by:
hi.....i have this script (below #1) that is linked to another php file SimpleImage.php (#2) im trying to get it to work on my uploaded images but it keeps coming up errors.....i haven't altered anything except for: $image->load('picture.jpg'); $image->resize(546,403); $image->save('picture2.jpg'); I put the variables i need in there within " " instead of ' ' and i always get a error message.....am i doing something or cant...
0
8668
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9152
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9014
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4358
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2320
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.