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.