Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use PHP to generate thumbnails of pictures

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to use PHP to generate thumbnails of pictures, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

Function: support jpg,jpeg,gif,png,bmp picture format, support scaling according to the proportion of the original picture, you can choose whether the picture needs to be cut in the process of picture scaling, adding picture quality control, you can achieve the highest quality of thumbnail pictures. The code for the complete class is as follows:

The method is simple and the code is as follows:

$resizeimage=new ResizeImage ('upload/abc.bmp',' 120,'90,'0, 'upload/xabc.bmp')

Another powerful PHP picture thumbnail class: phpThumb

In addition to zooming pictures, this class can also convert pictures to different formats (for example, output pictures in GIF format to PNG format). Its features also include colors, special effects and so on.

Official website: http://phpthumb.sourceforge.net/

We'll be using phpThumb, the open source PHP script to generate thumbnails on the fly.

Download and extract phpThumb to somewhere in your website folder. Now to use a rounded corner thumbnail of an image, simply use the img tag of HTML with src as

Adjust the path to phpThumb according to where you place the phpThumb files.

Usually only the following files are needed.

In fact, phpThumb is a little more powerful than I thought. Here is a list of some of its other useful parameters:

Src: the address of the target image

W: the width of the output picture

H: the height of the output picture (if it is not specified, it will be scaled proportionally by the w parameter)

Q: if the output is in JPG format, you can specify its output quality

Bg: the background of the output (if required)

Sw, sh, sx, sy: local output, width and height, start position

F: output format, which can be jpeg, png, gif, ico

Sfn: output a frame in a gif animation

Fltr []: filters can have many effects, including sharpening, blurring, flipping, watermarking, frame, shading, color adjustment, etc.

Use the demo:

/ / load the class library file require_once 'path/to/ThumbLib.inc.php'; / / instantiate the class library, and pass the address of the image you want to process to either the network address or the local address $thumb = PhpThumbFactory::create (' https://cache.yisu.com/upload/information/20201209/266/41614.jpg') Thank you for reading this article carefully. I hope the article "how to use PHP to generate thumbnails of pictures" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report