The Netlobo logo - a Nevada desert landscape

Comments for Resizing an Image Using PHP and the GD2 Library

< Back to the article

5 comments for this article.

RSS Feed Icon Subscribe to the comments for this article

Posted: 2007-12-05 07:42:42 by Dahool
Dude.. you saved my day xD

Excelent resize Function!

Can you manage the quality of the image? like 66% when resized to 800 x 600?
Posted: 2007-12-05 07:53:28 by lobo235 - Netlobo Staff Member
To change the quality of the image look for this line toward the bottom of the function:

if( !imagejpeg( $img_dst, $destfile, 90 ) )

The number 90 indicates the quality of the JPEG image that will be saved. The possible values that you could replace it with are 0-100 with 100 being the highest quality.

You could also add a $quality parameter to the function and pass in the quality of the image to be saved. In this case you would just replace the number 90 with the variable $quality. If you want to implement a default value if the $quality is not passed then the function declaration would look like this:

function resampimagejpg( $forcedwidth, $forcedheight, $sourcefile, $destfile, $quality = 90 )

I hope this helps!
Posted: 2007-12-05 10:20:47 by Dahool
yeah I've figured it out a few minutes later after I've made thee first post!!

Thank you a lot!!

=)
Posted: 2007-12-10 12:15:25 by ahhoi
sounds very promising! can't get ir trunning though as I don't know how to "must pass in the forced width, forced height, source image, and destination image" in the right format (including path?). sorry, php newbie here ... thx fo any more comments!
Posted: 2007-12-10 12:18:11 by lobo235 - Netlobo Staff Member
The forced width and forced height are measured in pixels. So if you want the resized image to fit in a 640x640 box you would pass the number 640 for both parameters. The source image and destination image should be passed in with either the full path or the path relative to the php script.

Are you getting a specific error when you try to use the function?

RSS Feed Icon Subscribe to the comments for this article

Post your comment for the Resizing an Image Using PHP and the GD2 Library article:

Name (required) (letters and numbers only):
Email (required) (will not be published):
Website (include http://):
Comment (required): (HTML tags allowed: pre, strong, em, b, i)