PHP pictures and other proportional zoom release into thumbnail function share _php instances

Source: Internet
Author: User
Copy CodeThe code is as follows:
/*
* @im//Picture resources that need to be scaled
* @filetype//production of thumbnail file type
* @dstimW//Zoom the width of the picture
* @dstimH//height of the picture to zoom
* @thumbname//thumbnail file name
function Makethumb ($im, $dstimW, $dstimH, $thumbname, $filetype) {
Get the width and height of IM
$pic _w=imagesx ($im);
$pic _h=imagesy ($im);
$arr = Array ();
Swith ($filetype) {
Case ' jpg ':
$arr [$filetype]= "imagejpeg";
Break
Case ' PNG ';
$arr [$filetype]= "Imagepng";
Break
Case ' Jif ';
$arr [$filetype]= "Imagegif";
}
if ($dstimgW && $dstimgW < $pic _w) | | ($dstimgH && $dstimgH < $pic _h)) {
if ($dstimgW && $dstimgW < $pic _w) {
$dsimgWratio = $dstimgW/$pic _w;
$resizereagW =true;

}
if ($dstimgH && $ $dstimgH < $pic _h) {
$dsimgHratio = $dstimgH/$pic _h;
$resizerreagH =true;
}
//thumbnail width height and original aspect ratio, whichever is the smallest
if ($resizereagW && $resizerreagH) {
if ($dsimgWratio < $dsimgHratio)
$ Radio = $dsimgWratio;
Else
$radio = $dsimgHratio;
}
if ($resizereagW &&! $resizerreagH) {
$radio = $dsimgWratio;
}
if (! $resizereagW && $resizerreagH) {
$radio = $dsimgHratio;
}
$imgnewW = $pic _w * $radio;
$imgnewH = $pic _h * $radio;
if (function_exists ("imgcopyresampled")) {
//Create target resource canvas
$dst = Imagecreatetruecolor ($imgnewW, $imgnewH);
Imagecopyresampled ($DST, $im, 0,0,0,0, $imgnewW, $imgnewH, $pic _w, $pic _h);
}else{
$dst =imagecreate ($imgnewW, $imgnewH),
imagecopyresized ($DST, $im, 0,0,0,0, $imgnewW, $imgnewH, $ IMGNEWH, $pic _w, $pic _h);
}

$arr [$filetype] ($DST, $thumbname. ". $filetype ");
Imagedestroy ($DST);
}else{//the width and height of the thumbnail itself is greater than the width and height of the original image
The width and height of the thumbnail is the height of the original image and the original
$arr [$filetype] ($im, $thumbname. ". $filetype ");
Imagedestroy ();
}
}
?>

  • 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.