PHP by the specified size and so on to release to upload image thumbnails _php tutorial

Source: Internet
Author: User
Tags imagejpeg
PHP Tutorial by the specified size and so on to release into a thumbnail image upload
/**
* *
* Equal to zoom
* @param unknown_type $srcImage Source picture path
* @param unknown_type $toFile target picture path
* @param unknown_type $maxWidth Maximum width
* @param unknown_type $maxHeight Maximum height
* @param unknown_type $imgQuality picture quality
* @return Unknown
*/

Function Resize ($srcImage, $toFile, $maxWidth =, $maxHeight = +, $imgQuality =100)
{

List ($width, $ Height, $type, $attr) = getimagesize ($srcImage);
if ($width < $maxWidth | | $height < $maxHeight) return;
Switch ($type) {
Case 1: $img = Imagecreatefromgif ($srcImage), break,
Case 2: $img = Imagecreatefromjpeg ($src Image); Break
Case 3: $img = Imagecreatefrompng ($srcImage);
}
$scale = min ($maxWidth/$width, $maxHeight/$height);//Find bloom ratio

if ($scale < 1) {
$newWidth = floor ($scale * $width);
$newHeight = Floor ($scale * $height);
$NEWIMG = Imagecreatetruecolor ($newWidth, $newHeight);
imagecopyresampled ($newImg, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
$newName = "";
$toFile = Preg_replace ("/(. gif|. Jpg|. Jpeg|. PNG)/I "," ", $toFile);

Switch ($type) {
Case 1:if (Imagegif ($newImg, "$toFile $newname.gif", $imgQuality))
Return "$newName. gif"; Break
Case 2:if (imagejpeg ($newImg, "$toFile $newname.jpg", $imgQuality))
Return "$newName. jpg"; Break
Case 3:if (Imagepng ($newImg, "$toFile $newname.png", $imgQuality))
Return "$newName. png"; Break
Default:if (imagejpeg ($newImg, "$toFile $newname.jpg", $imgQuality))
Return "$newName. jpg"; Break
}
Imagedestroy ($NEWIMG);
}
Imagedestroy ($IMG);
return false;
}


http://www.bkjia.com/PHPjc/444947.html www.bkjia.com true http://www.bkjia.com/PHPjc/444947.html techarticle PHP Tutorial by the specified size and so on to release into the image thumbnail/** * * * * Zoom * @param unknown_type $srcImage Source Picture path * @param unknown_type $toFile destination picture path ...

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