<?php
Picture's equal scaling
Because PHP can only operate on resources, copy the picture that needs to be scaled to create a new resource
$src =imagecreatefromjpeg (' a.jpg ');
Get the width and height of the source picture
$size _src=getimagesize (' a.jpg ');
$w = $size _src[' 0 '];
$h = $size _src[' 1 '];
Specifies the maximum width to zoom out (and possibly the height)
$max = 300;
Calculates the length of the other side based on the maximum value of 300, and gets the scaled picture width and height
if ($w > $h) {
$w = $max;
$h = $h * ($max/$size _src[' 0 ']);
}else{
$h = $max;
$w = $w * ($max/$size _src[' 1 ']);
}
Declare a $w wide, $h high true Color picture resources
$image =imagecreatetruecolor ($w, $h);
Key functions, parameters (target resource, source, target resource start coordinate x,y, source resource start coordinate x,y, target resource's width high w,h, source resource's width high w,h)
Imagecopyresampled ($image, $src, 0, 0, 0, 0, $w, $h, $size _src[' 0 '], $size _src[' 1 ']);
Tell the browser to parse it in the form of a picture
Header (' content-type:image/png ');
Imagepng ($image);
Destroying resources
Imagedestroy ($image);
?>