A php code for generating thumbnails proportionally

Source: Internet
Author: User

A php thumbnail generated proportionally. In this article, image is the image address you want to generate. This is a php thumbnail generated proportionally, only images of the specified size can be generated without deformation of the ekt.

A php tutorial generates thumbnail code proportionally

In this article, image is the image address you want to generate. This is a php code for generating thumbnails in proportion. You only need to provide images to generate images of the specified size without changing the ekt.
*/

Function resizeimage ($ image, $ width, $ height, $ scale ){
List ($ imagewidth, $ imageheight, $ imagetype) = getimagesize ($ image );
$ Imagetype = image_type_to_mime_type ($ imagetype );
$ Newimagewidth = ceil ($ width * $ scale );
$ Newimageheight = ceil ($ height * $ scale );
$ Newimage = imagecreatetruecolor ($ newimagewidth, $ newimageheight );
Switch ($ imagetype ){
Case "image/gif ":
$ Source = imagecreatefromgif ($ image );
Break;
Case "image/pjpeg ":
Case "image/jpeg ":
Case "image/jpg ":
$ Source = imagecreatefromjpeg ($ image );
Break;
Case "image/png ":
Case "image/x-png ":
$ Source = imagecreatefrompng ($ image );
Break;
}
Imagecopyresampled ($ newimage, $ source, 0, 0, 0, $ newimagewidth, $ newimageheight, $ width, $ height );
 
Switch ($ imagetype ){
Case "image/gif ":
Imagegif ($ newimage, $ image );
Break;
Case "image/pjpeg ":
Case "image/jpeg ":
Case "image/jpg ":
Imagejpeg ($ newimage, $ image, 90 );
Break;
Case "image/png ":
Case "image/x-png ":
Imagepng ($ newimage, $ image );
Break;
}
 
Chmod ($ image, 0777 );
Return $ image;
}
?>

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.