Home > Web Front-end > JS Tutorial > Example of proportional scaling of database images with php and js_javascript skills

Example of proportional scaling of database images with php and js_javascript skills

WBOY
Release: 2016-05-16 16:50:58
Original
1744 people have browsed it
JS proportional scaling of an image

Code
Copy code The code is as follows:

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)

534 X 800

./img/IMG_20140424_200722.jpg" target="_blank">200 , the image will not be enlarged and displayed (displayed according to the original image)<br /> <br>The original image is 444 x 207, compressed to 500 x 600, and the original image will be displayed<br /> <br>onload =
444 X 207
< ;br />





PHP proportional scaling of database images


Copy codefunction 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");

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