Share on Google+Share on Google+

PHP GD Image Resize

This example shows how to Images resize and save image in php gd.


$file = 'images.jpg';

$save = 'new.jpg';

list($width, $height) = getimagesize($file) ;

$modwidth = 100;

$modheight = 100;

$tn = imagecreatetruecolor($modwidth, $modheight) ;

$image = imagecreatefromjpeg($file) ;

imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;

imagejpeg($tn, $save, 100);

echo("Image created and saved successfully.");


After running the program you will get the following output


Posted on: November 11, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.