Maison  >  Article  >  développement back-end  >  Thinkphp调用Image类生成缩略图的方法,thinkphpimage_PHP教程

Thinkphp调用Image类生成缩略图的方法,thinkphpimage_PHP教程

WBOY
WBOYoriginal
2016-07-13 10:05:251000parcourir

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

本文实例讲述了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);

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

希望本文所述对大家的php程序设计有所帮助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/963825.htmlTechArticleThinkphp调用Image类生成缩略图的方法,thinkphpimage 本文实例讲述了Thinkphp调用Image类生成缩略图的方法。分享给大家供大家参考。具体分析如下...
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn