This article mainly introduces how Thinkphp calls the Image class to generate thumbnails. The example analyzes the usage principle and related skills of Thinkphp to call the Image class to generate thumbnails, for more information about how Thinkphp calls the Image class to generate thumbnails, see the example in this article. Share it with you for your reference. The specific analysis is as follows:
The Image class of Thinkphp is in ThinkPHP/Extend/Library/ORG/Util/Image. class. php.
The call method is as follows:
Import ("ORG. util. image "); $ Img = new Image (); // instantiate an Image class object $ image_path = '. /Image path '; // if the current php file is in the APP_PATH path of Thinkphp //'. /'is the index. php file. // Because APP_PATH is defined and loaded through index. php. $ Image_info = $ Img: getImageInfo ($ image_path); // Obtain image information
The getImageInfo method obtains the width, height, type, size, mime, and other information of the image.
Creating thumbnails is simple.
The parameter requires img_path (source image path), thumb_name (thumbnail name, including Path), thumb_type (image type), Max_width (width), and Max_height (height ):
// Generate a thumbnail: $ Img: thumb2 ($ img_path, $ thumb_name, $ thumb_type, $ Max_width, $ Max_height );
Note that the width and height of the thumbnail cannot be greater than that of the source image. Otherwise, the generation will fail.
I hope this article will help you with php programming.