Thinkphp调用Image类生成缩略图的方法

Thinkphp的Image类 在ThinkPHP/Extend/Library/ORG/Util/Image.class.php中。

调用方法如下:

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);//获取图片信息

getImageInfo方法会获取图片的width,height,type,size,mime等信息。

缩略图的生成很简单。

参数需要img_path(原图路径),thumb_name(缩略图名,包含路径),thumb_type(图片类型),Max_width(宽),Max_height(高):

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

需要注意的是,缩略图的宽和高不能比原图的大,不然就会生成失败

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/26ddc47fe509b53ef0755b7670cd402f.html