JS to the equal ratio of a picture zoom
Code
Code highlighting produced by Actipro Codehighlighter (freeware) http://www.codehighlighter.com/-->
The latest JavaScript automatically displays pictures proportionally, proportionally compresses the picture display
Original display (534 X 800)
Onload= "Autoresizeimage (0,0,this)
3. Proportional compression by height 250 width 250
Onload= "Autoresizeimage (250,250,this)"
6. If the height and width of the picture are less than the maximum height and width of the compression, the picture will not be pulled up (shown by the original)
Original 444 x 207, compressed to x 600, will keep the original display
Onload= "Autoresizeimage (500,600,this)"
PHP-to-database image scaling
!--? php
class imgsf{
function make_img ($img _address) {
//Picture magnification
//Because PHP can only operate on resources, So copy the picture that needs to be scaled, create the new resource
$src =imagecreatefromjpeg ($img _address);
//Get the width and height of the source picture
$size _src=getimagesize ($img _address),
$w = $size _src[' 0 '];
$h = $size _src[' 1 '];
//Specifies the maximum width (and possibly height) of the zoom out
$max =300;
//Based on the maximum value of 300, the length of the other edge is calculated, the image width and height after zooming
if ($w > $h) {
$w = $max;
$h = $h * ($max/$size _src[' 0 '));
} else{
$h = $max;
$w = $w * ($max/$size _src[' 1 ']);
}
//Declare a $w-wide, $h-high true Color picture resource
$image =imagecreatetruecolor ($w, $h);
//Key function, parameter (target resource, source, start coordinate of target resource x, y, start coordinate of source resource x, y, Width height of target resource w,h, width of source resource w,h)
imagecopyresampled ($image, $src, 0, 0, 0, 0, $w, $h, $size _src[' 0 '], $size _src[' 1 ']);
//Tell the browser to parse the
header (' Content-type:image/png ') as an image,
Imagepng ($image);
//Destroy Resource
Imagedestroy ($image);
}
}
$obj =new imgsf ();
$obj->make_img ("./img/img_20140424_200722.jpg");