JS proportional scaling of an image Code
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
Latest javascript Automatically display images proportionally and compress images proportionally
Original image display (534 X 800)
onload="AutoResizeImage(0 ,0,this)
./img/IMG_20140424_200722.jpg" target="_blank">
< ;br />
PHP proportional scaling of database images
Copy code
function make_img($img_address ){
//Constantial scaling of pictures
//Because PHP can only operate on resources, you need to copy the pictures that need to be scaled and create them as new resources
$src =imagecreatefromjpeg($img_address);
//Get the width and height of the source image
$size_src=getimagesize($img_address);
$w=$size_src['0'];
$h=$size_src['1'];
//Specify the maximum width (maybe height) of scaling
$max=300;
//According to The maximum value is 300, calculate the length of the other side, and 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']) ;
}
//Declare a true color image resource of $w width and $h height
$image=imagecreatetruecolor($w, $h);
//Key function, parameters (target resource, source, starting coordinates x,y of the target resource, starting coordinates x,y of the source resource, width and height w,h of the target resource, width and height w of the source resource, h)
imagecopyresampled($image, $src, 0, 0, 0, 0, $w, $h, $size_src['0'], $size_src['1']);
//Tell the browser to parse
header('content-type:image/png');
imagepng($image);
//Destroy resources
imagedestroy($ image);
}
}
$obj=new ImgSF();
$obj->make_img("./img/IMG_20140424_200722.jpg");