PHP image proportional scaling instance. Copy the code as follows :? Php image proportional scaling because PHP can only operate on resources, so you need to copy the image to be scaled and create a new resource $ srcim
The code is as follows:
// Proportional scaling of the image
// Because PHP can only operate on resources, you need to copy the image to be scaled and create a new resource.
$Src?imagecreatefrom=('a.jpg ');
// Obtain the width and height of the source image
$Size_src1_getimagesize('a.jpg ');
$ W = $ size_src ['0'];
$ H = $ size_src ['1'];
// Specify the scaled width (or the height)
$ Max = 300;
// Calculate the length of the other side based on the maximum value of 300 to obtain the scaled image 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 width, $ h high real color image resource
$ Image = imagecreatetruecolor ($ w, $ h );
// Key functions, parameters (start coordinates x and y of the target resource, source resource, and target resource, and start coordinates x and y of the source resource, w, h, SOURCE Resource width/height w, h)
Imagecopyresampled ($ image, $ src, 0, 0, 0, $ w, $ h, $ size_src ['0'], $ size_src ['1']);
// Tell the browser to parse the image
Header ('content-type: image/png ');
Imagepng ($ image );
// Destroy resources
Imagedestroy ($ image );
?>
The http://www.bkjia.com/PHPjc/326717.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/326717.htmlTechArticle code is as follows :? Php // proportional scaling of images // because PHP can only perform operations on resources, you need to copy the image to be scaled and create a new resource $ src = im...