Home  >  Article  >  Backend Development  >  Thinkphp calls the Image class to generate thumbnails, thinkphpimage_PHP tutorial

Thinkphp calls the Image class to generate thumbnails, thinkphpimage_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:05:251040browse

Thinkphp calls the Image class to generate thumbnails, thinkphpimage

This article describes the example of Thinkphp calling the Image class to generate thumbnails. Share it with everyone for your reference. The specific analysis is as follows:

Thinkphp’s Image class is in ThinkPHP/Extend/Library/ORG/Util/Image.class.php.

The calling method is as follows:

import("ORG.Util.Image");
$Img = new Image();//实例化图片类对象
$image_path = './图片路径';
//若当前php文件在Thinkphp的中APP_PATH路径中
//'./'就是index.php的上一级文件。
//因为APP_PATH是通过index.php定义和加载的。
$image_info = $Img::getImageInfo($image_path);//获取图片信息

The getImageInfo method will obtain the width, height, type, size, mime and other information of the image.

Thumbnail generation is easy.

The parameters require img_path (original image path), thumb_name (thumbnail name, including path), thumb_type (picture type), Max_width (width), Max_height (height):

//生成缩略图:
$Img::thumb2($img_path,$thumb_name,$thumb_type,$Max_width,$Max_height);

It should be noted that the width and height of the thumbnail cannot be larger than the original image, otherwise the generation will fail

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/963825.htmlTechArticleThinkphp calls the Image class to generate thumbnails, thinkphpimage This article describes the method of Thinkphp calling the Image class to generate thumbnails . Share it with everyone for your reference. The specific analysis is as follows...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn