Examples of proportional image scaling in PHP_PHP tutorial

WBOY
Release: 2016-07-21 15:12:28
Original
734 people have browsed it

Copy code The code is as follows:

//Isometric scaling of images

//Because PHP can only operate on resources, you need to copy the image that needs to be scaled and create it as a new resource
$src=imagecreatefromjpeg('a.jpg');

//Get the width and height of the source image
$size_src=getimagesize('a.jpg');
$w=$size_src['0'];
$h=$size_src['1' ; Length, get 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']);
}

       
                                                                                                                                (Target resource, source, start coordinates x, y of the target resource, start coordinates x, y of the source resource, width and height w, h of the target resource, width and height w, h of the source resource)
Imagecopyresampled($image, $src, 0, 0, 0, 0, $w, $h, $size_src['0'], $size_src['1']);

//Tell the browser to parse as an image
header('content-type:image/png');
imagepng($image);

//Destroy resources
imagedestroy($image);

? >







http://www.bkjia.com/PHPjc/326717.html
www.bkjia.com

truehttp: //www.bkjia.com/PHPjc/326717.html

TechArticleCopy the code code as follows: ?php //Isometric scaling of images//Because PHP can only operate on resources , so you need to copy the image that needs to be scaled and create it as a new resource $src=im...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template