thinkphp调用image类生成缩略图的方法 这篇文章主要介绍了thinkphp调用image类生成缩略图的方法,实例分析了thinkphp调用image类生成缩略图的使用原理与相关技巧,需要的朋友可以参考下
本文实例讲述了thinkphp调用image类生成缩略图的方法。分享给大家供大家参考。具体分析如下:
thinkphp的image类 在thinkphp/extend/library/org/util/image.class.php中。
调用方法如下:
?
1
2
3
4
5
6
7
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(高):
?
1
2
//生成缩略图:
$img::thumb2($img_path,$thumb_name,$thumb_type,$max_width,$max_height);
需要注意的是,缩略图的宽和高不能比原图的大,不然就会生成失败
希望本文所述对大家的php程序设计有所帮助。
http://www.bkjia.com/phpjc/963973.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/963973.htmltecharticlethinkphp调用image类生成缩略图的方法 这篇文章主要介绍了thinkphp调用image类生成缩略图的方法,实例分析了thinkphp调用image类生成缩略图的使用...