Create multiple thumbnails of a single picture and save

Source: Internet
Author: User

Code:

$filename = "des_big.jpg"; list ($src _w, $src _h, $imagetype) =getimagesize ($filename); $mime =image_type_to_mime_type ($ imagetype);//echo $mime;//output is Imae/jpeg$createfun=str_replace ("/", "CreateFrom", $mime);//imagejpeg () $outFun =str_ Replace ("/", NULL, $mime), $src _image= $createFun ($filename); $dst _50_image=imagecreatetruecolor (50,50); $DST _220_ Image=imagecreatetruecolor (220,220); $dst _350_image=imagecreatetruecolor (350,350); $DST _800_image= Imagecreatetruecolor (800,800) imagecopyresampled ($dst _50_image, $src _image,0,0,0,0,50,50, $src _w, $src _h); Imagecopyresampled ($dst _220_image, $src _image,0,0,0,0,220,220, $src _w, $src _h); imagecopyresampled ($dst _350_image, $src _image,0,0,0,0,350,350, $src _w, $src _h) imagecopyresampled ($dst _800_image, $src _image,0,0,0,0,800,800, $src _w, $src _h); $outFun ($dst _50_image, "uploads/image_50/". $filename); $outFun ($dst _220_image, "uploads/image_220/". $ filename); $outFun ($dst _350_image, "uploads/image_350/". $filename); $outFun ($dst _800_image, "Uploads/image_800/". $ filename); Imagedestroy ($src _image); IMAgedestroy ($dst _50_image); Imagedestroy ($dst _220_image); Imagedestroy ($dst _350_image); Imagedestroy ($dst _800_ image);

Finally, a picture of 50*50,220*220,350*350,800*800 is generated and there are uploads/image_50, uploads/image_220, uploads/image_350, Uploads/image, respectively. _800 in the folder.

The function description in the code:

Image_type_to_mime_type-gets the MIME type of the image type returned by Getimagesize,exif_read_data,exif_thumbnail,exif_imagetype

Create multiple thumbnails of a single picture and save

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.