Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-13 09:13:31
Original
1239 people have browsed it

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程序设计有所帮助。

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!