To generate image thumbnails using PHP, make sure that the GD2 graphics library is installed on your PHP server to generate image thumbnails using a class.
1. usage
$ Resizeimage = new resizeimage ("Image source file address", "200", "100", "0", "thumbnail address"); // only use the preceding sentence, you can generate a thumbnail. the source file and the thumbnail address can be the same. 200,100 represents the width and height respectively.
2. php code
// Use the following classes to generate image thumbnails,
Srcimg = $ img; $ this-> resize_width = $ wid; $ this-> resize_height = $ hei; $ this-> cut = $ c; // Image type $ this-> type = strtolower (substr (strrchr ($ this-> srcimg ,". "), 1); // initialize the image $ this-> initi_img (); // The destination image address $ this-> dst_img ($ dstpath ); // -- $ this-> width = imagesx ($ this-> im); $ this-> height = imagesy ($ this-> im ); // generate an image $ this-> newimg (); ImageDestroy ($ this-> im);} function newimg () {// ratio of the changed image $ resize_ratio = ($ This-> resize_width)/($ this-> resize_height); // ratio of the actual image $ ratio = ($ this-> width) /($ this-> height); if ($ this-> cut) = "1") // cut graph {if ($ ratio> = $ resize_ratio) // height first {$ newimg = imagecreatetruecolor ($ this-> resize_width, $ this-> resize_height); imagecopyresampled ($ newimg, $ this-> im, 0, 0, 0, 0, 0, $ this-> resize_width, $ this-> resize_height, ($ this-> height) * $ resize_ratio), $ this-> height); ImageJpeg ($ newimg, $ th Is-> dstimg);} if ($ ratio <$ resize_ratio) // width first {$ newimg = imagecreatetruecolor ($ this-> resize_width, $ this-> resize_height ); imagecopyresampled ($ newimg, $ this-> im, 0, 0, 0, 0, $ this-> resize_width, $ this-> resize_height, $ this-> width, ($ this-> width)/$ resize_ratio); ImageJpeg ($ newimg, $ this-> dstimg );}} else // uncut graph {if ($ ratio >=$ resize_ratio) {$ newimg = imagecreatetruecolor ($ this-> resize_width, ($ thi S-> resize_width)/$ ratio); imagecopyresampled ($ newimg, $ this-> im, 0, 0, 0, 0, $ this-> resize_width, ($ this-> resize_width)/$ ratio, $ this-> width, $ this-> height); ImageJpeg ($ newimg, $ this-> dstimg );} if ($ ratio <$ resize_ratio) {$ newimg = imagecreatetruecolor ($ this-> resize_height) * $ ratio, $ this-> resize_height); imagecopyresampled ($ newimg, $ this-> im, 0, 0, 0, 0, ($ this-> resize_height) * $ ratio, $ this-> resiz E_height, $ this-> width, $ this-> height); ImageJpeg ($ newimg, $ this-> dstimg) ;}}// initialize the image function initi_img () {if ($ this-> type = "jpg") {$ this-> im = imagecreatefromjpeg ($ this-> srcimg );} if ($ this-> type = "gif") {$ this-> im = imagecreatefromgif ($ this-> srcimg );} if ($ this-> type = "png") {$ this-> im = imagecreatefrompng ($ this-> srcimg );}} // function dst_img ($ dstpath) {$ full_length = strlen ($ th Is-> srcimg); $ type_length = strlen ($ this-> type); $ name_length = $ full_length-$ type_length; $ name = substr ($ this-> srcimg, 0, $ name_length-1); $ this-> dstimg = $ dstpath; // echo $ this-> dstimg ;}}?>