Three modes for generating thumbnails in php-PHP source code

Source: Internet
Author: User
Three modes for generating thumbnails in php: 1. scale down a large image to the specified range of the thumbnail, which may be left white (the details of the original image are not lost)
2. scale down a large image to the specified range of the thumbnail without leaving it blank (the original image is scaled in the center and the excess part is cropped out)
3. scale down a large image to the specified range of the thumbnail and leave it blank (the source image will cut the right and bottom of the non-conforming proportion)

Thumb_stand.php

 'Gif', 2 => 'jpeg ', 3 => 'PNG'); list ($ fw, $ fh, $ tmp) = getimagesize ($ f); if (! $ Temp [$ tmp]) {return false;} $ tmp = $ temp [$ tmp]; $ infunc = "imagecreatefrom $ tmp"; $ outfunc = "image $ tmp "; $ fimg = $ infunc ($ f); // do not deform the scaled image, if ($ fw/$ tw> $ fh/$ th) {$ th = $ tw * ($ fh/$ fw );} else {$ tw = $ th * ($ fw/$ fh);} $ timg = imagecreatetruecolor ($ tw, $ th); imagecopyresampled ($ timg, $ fimg, 0, 0, 0, 0, $ tw, $ th, $ fw, $ fh); if ($ outfunc ($ timg, $ t) {return true ;} else {return false ;}}?>


Thumb_cut.php

 'Gif', 2 => 'jpeg ', 3 => 'PNG'); list ($ fw, $ fh, $ tmp) = getimagesize ($ f); if (! $ Temp [$ tmp]) {return false;} $ tmp = $ temp [$ tmp]; $ infunc = "imagecreatefrom $ tmp"; $ outfunc = "image $ tmp "; $ fimg = $ infunc ($ f); // $ fw = 10; // $ fh = 4; // $ tw = 4; // $ th = 2; // fill the image in the area to be scaled. if ($ fw/$ tw> $ fh/$ th) {$ zh = $ th; $ zw = $ zh * ($ fw/$ fh); $ _ zw = ($ zw-$ tw)/2;} else {$ zw = $ tw; $ zh = $ zw * ($ fh/$ fw); $ _ zh = ($ zh-$ th)/2;} // echo $ zw."
"; // Echo $ zh ."
"; // Echo $ _ zw ."
"; // Echo $ _ zh ."
"; // Exit; $ zimg = imagecreatetruecolor ($ zw, $ zh); // first, the image is filled with imagecopyresampled ($ zimg, $ fimg, 0, 0, 0, 0, $ zw, $ zh, $ fw, $ fh); // capture the specified width and height $ timg = imagecreatetruecolor ($ tw, $ th); imagecopyresampled ($ timg, $ zimg, 0, 0 + $ _ zw, 0 + $ _ zh, $ tw, $ th, $ zw-$ _ zw * 2, $ zh-$ _ zh * 2 ); // if ($ outfunc ($ timg, $ t) {return true ;}else {return false ;}}?>


Thumb_strict.php

 'Gif', 2 => 'jpeg ', 3 => 'PNG'); list ($ fw, $ fh, $ tmp) = getimagesize ($ f); if (! $ Temp [$ tmp]) {return false;} $ tmp = $ temp [$ tmp]; $ infunc = "imagecreatefrom $ tmp"; $ outfunc = "image $ tmp "; $ fimg = $ infunc ($ f); if ($ fw/$ tw> $ fh/$ th) {$ fw = $ tw * ($ fh/$ th );} else {$ fh = $ th * ($ fw/$ tw);} $ timg = imagecreatetruecolor ($ tw, $ th); imagecopyresampled ($ timg, $ fimg, 0, 0, 0, 0, $ tw, $ th, $ fw, $ fh); if ($ outfunc ($ timg, $ t) {return true ;} else {return false ;}}?>


[File] thumb_image.rar

Thumb_image.rar

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.