Personal tools

Resizing an Image with PHP





Resizing an image in PHP is made possible by the GD library.  Most PHP configurations include the GD extension.

The following code should be a good guide:


$quality = 75;

$new_width = 600;

$new_height = 400;

$src = "image/original-image";

$dest = "image/resized-image.jpg";

$dest_resource = ImageCreateTrueColor($new_width,$new_height);

$src_resource = ImageCreateFromJpeg($src);

list($src_w, $src_h) = GetImageSize($src);

ImageCopyResampled($dest_resource, $src_resource, 0, 0, 0, 0, $new_width, $new_height, $src_w, $src_h);

imagejpeg($dest_resource, $dest, $quality);


Example that uses the above code:
Resize jpg online

Need assistance with your project? Universal Web Services can help.
Contact us to request a quote.