Thinkphp calls the Image class to generate thumbnails.

Source: Internet
Author: User
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.

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: 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.