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