PHP and JS to zoom in on the database image

Source: Internet
Author: User
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");

  • Contact Us

    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

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.