Php simple thumbnail class | image. class. php. How to use: unzip imgnewiamge$img-resize(dstimg.jpg, srcimg.jpg, 300,400); Note: This is scaled in proportion, dstimg.jpgis the target file, srcimg.jpg is the source file, and the following method is used:
$ Img = new iamge;
$ Img-> resize('dstimg.jpg ', 'srcimg.jpg', 300,400 );
Note: dstimg.jpg is the target file, and srcimg.jpg is the source file, followed by the width and height of the target file.
$ Img-> thumb('dstimg.jpg ', 'scrimg.jpg', 300,300 );
Note: This is a pay-as-you-go chart. dstimg.jpg is the target file, and srcimg.jpg is the source file, followed by the width and height of the target file.
This is so troublesome for the GD Library. if Imagick is used, you only need two functions to implement the above functions. you can find it by checking the document.
Class image {
Public function resize ($ dstImg, $ srcImg, $ dstW, $ dsomething ){
List ($ srcW, $ srcH) = getimagesize ($ srcImg );
$ Scale = min ($ dstW/$ srcW, $ dsomething/$ srcH );
$ NewW = round ($ srcW * $ scale );
$ NewH = round ($ srcH * $ scale );
$ NewImg = imagecreatetruecolor ($ newW, $ newH );
$ SrcImg = imagecreatefromjpeg ($ srcImg );
Imagecopyresampled ($ newImg, $ srcImg, 0, 0, 0, $ newW, $ newH, $ srcW, $ srcH );
Imagejpeg ($ newImg, $ dstImg );
}
Public function thumb ($ dstImg, $ srcImg, $ dstW, $ dsomething ){
List ($ srcW, $ srcH) = getimagesize ($ srcImg );
$ Scale = max ($ dstW/$ srcW, $ dsomething/$ srcH );
$ NewW = round ($ dstW/$ scale );
$ NewH = round ($ dsomething/$ scale );
$ X = ($ srcW-$ newW)/2;
$ Y = ($ srcH-$ newH)/2;
$ NewImg = imagecreatetruecolor ($ dstW, $ dsomething );
$ SrcImg = imagecreatefromjpeg ($ srcImg );
Imagecopyresampled ($ newImg, $ srcImg, 0, 0, $ x, $ y, $ dstW, $ dsomething, $ newW, $ newH );
Imagejpeg ($ newImg, $ dstImg );
}
}
Function createFromType ($ type, $ srcImg ){
$ Function = "imagecreatefrom $ type ";
Return $ function ($ srcImg );
}
// To solve the problem of different image formats
Export $ img = new iamge; export img-resize('dstimg.jpg ', 'srcimg.jpg', 300,400); Note: This is scaled in proportion, dstimg.jpgis the target file, srcimg.jpg is the source file, followed...