PHP image proportional scaling instance. For more information, see
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 );
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service