Home >Backend Development >PHP Tutorial >Thinkphp calls the Image class to generate thumbnails_PHP tutorial

Thinkphp calls the Image class to generate thumbnails_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:05:15905browse

How Thinkphp calls the Image class to generate thumbnails

This article mainly introduces the method of Thinkphp calling the Image class to generate thumbnails, and an example analysis of Thinkphp calling the Image class to generate thumbnails Friends in need can refer to the usage principles and related techniques

The example in this article describes how Thinkphp calls 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:

?

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

1 2

3

4

5

6

7

1

2

//生成缩略图:

$Img::thumb2($img_path,$thumb_name,$thumb_type,$Max_width,$Max_height);

import("ORG.Util.Image"); $Img = new Image();//Instantiate image class object

$image_path = './image path';

//If the current php file is in the APP_PATH path of Thinkphp

//'./' is the upper-level file of index.php. //Because APP_PATH is defined and loaded through index.php.

$image_info = $Img::getImageInfo($image_path);//Get image information
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):
?
1 2 //Generate thumbnail: $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. http://www.bkjia.com/PHPjc/963973.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/963973.htmlTechArticleThinkphp calls the Image class to generate thumbnails. This article mainly introduces the way Thinkphp calls the Image class to generate thumbnails. , the example analyzes the use of Thinkphp calling the Image class to generate thumbnails...
Statement:
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