Jump to content

Resizing image size with php


etrader

Recommended Posts

I use a simple php code (taken from php.net example) to resize an image

 

list($width, $height) = getimagesize($filename);
$new_height = $height / $width * 400;
$image_p = imagecreatetruecolor(400, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, 400, $new_height, $width, $height);
imagejpeg($image_p, "new.jpg");

 

Here, we create a blank image and merge it with the resized image. I wonder if it is the simplest way to resize and save an image. Is it really necessary to create a blank background image?

Link to comment
https://forums.phpfreaks.com/topic/250872-resizing-image-size-with-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.