Generate image thumbnail class written natively in PHP

little bottle
Release: 2023-04-05 21:08:01
forward
2068 people have browsed it

Generate image thumbnail class written natively in PHP. This article takes JD.com product images as an example to generate images of three different sizes. Calling the method is very simple, just pass the parameters height and width, and the name of the new picture.

Generate image thumbnail class written natively in PHP

Introducing the thumbnail class


##

1 include_once 'ImageResize.class.php';
Copy after login

Generate thumbnails of three different sizes Sketch


//实例化缩略图类 以京东商品为例 
$newimage = new ImageResize(); 
//将当前目录下的test.jpg生成缩略图并保存到test_400_400.jpg,指定的宽度高度分别是400和400像素 
$newimage->resize("test.jpg", "test_400_400.jpg", 400, 400); 
$newimage->resize("test.jpg", "test_200_200.jpg", 200, 200); 
$newimage->resize("test.jpg", "test_50_50.jpg", 50, 50); 
//获取最后一条错误信息,如果生成成功则输出'success' 
echo $newimage->GetLastError();
Copy after login

If you want to know more courses, please pay attention to the

PHP video tutorial on the PHP Chinese website!

The above is the detailed content of Generate image thumbnail class written natively in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template