How to change image size in PHP

Mainly through imagecreatetruecolor to achieve.

$filename = "./QR/$id.jpg";
$percent = 0.4;
list($width, $height) = getimagesize($filename);
$new_width = $width * $percent;
$new_height = $height * $percent;
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($image_p,'./images/thumb/'.$id.'.jpg');

filename is the file name;

percent is the reduction ratio;

imagejpeg saves the image for output.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325897162&siteId=291194637