Home >Backend Development >PHP Tutorial >PHPThumb image processing example_PHP tutorial

PHPThumb image processing example_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 10:30:45710browse

Download address (github.com/masterexploder/PHPThumb).
Note that this class library has the same name called phpThumb, the only difference is in upper and lower case, so be careful when searching for documentation.
In the process of website construction, there are countless places where images need to be processed. It is very cumbersome to use PHP image functions to process images. And it is very difficult for novices to master. Now we can use the PHPThumb class library to process images, including image resizing, image interception, image watermarking, image rotation and other functions.

Usage demonstration:

Copy code The code is as follows:

//Load class library file
require_once 'path /to/ThumbLib.inc.php';

//Instantiate the class library, the address of the image you want to process can be a network address or a local address
$thumb = PhpThumbFactory::create('http://www.jb51.net /');

//Reduce the image proportionally to the maximum width of 100px or up to 100px. When only one parameter is entered, it is the widest size limit.
$thumb->resize(100, 100);

//Reduce the image to the original percentage, for example, 50 is 50% of the original.
$thumb->resizePercent(50);

//Intercept a 175px * 175px picture. Note that this is an interception, and the excess part is directly cropped, not forced to change the size.
$thumb->adaptiveResize(175, 175);

//Calculate from the center of the image and intercept the 200px * 100px image.
$thumb->cropFromCenter(200, 100);

//Screenshot, the first two parameters are the coordinates X and Y of the upper right corner of the picture to be solved. The next two parameters are the width and height of the image that needs to be solved.
$thumb->crop(100, 100, 300, 200);

//Reverse the image 180 degrees clockwise
$thumb->rotateImageNDegrees(180);

//Save (generate) the image, you can save it in other formats, please refer to the document for details
$thumb->save( 'NewPath/Of/image.jpg ' );

This class library has more functions, so I won’t introduce them in detail. If you also need to process images when developing a PHP website, you may wish to read the documentation of this class library to ensure that it is very simple for you to process images, and you no longer have to deal with images. Dealing with those dozen annoying php image processing functions!


Another powerful PHP image thumbnail class: phpThumb

In addition to scaling images, this class can also convert images into different formats for output (such as outputting images in GIF format to PNG format). Its special features also include color, special effects, etc.
Official website: http: //phpthumb.sourceforge.net/

Generally you only need the following file:
[code]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.






[code]

In fact, the function of phpThumb is more powerful than I originally thought. Here are some other useful parameters List it out:
src: the address of the target image
w: the width of the output image
h: the height of the output image (if not specified, it will be scaled equally according to the w parameter)
q: output if It is in JPG format, and its output quality can be specified
bg: background during output (if needed)
sw, sh, sx, sy: partial output, width, height, starting position
f: output Format, can be jpeg, png, gif, ico
sfn: output a certain frame in the gif animation
fltr[]: filter, which can have many effects, including sharpening, blurring, rotation, watermark, Borders, masking, color adjustments, etc.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/764625.htmlTechArticleDownload address (github.com/masterexploder/PHPThumb). Note that this class library has an identical name called phpThumb, the only difference is in upper and lower case, so be careful when searching for documentation. On the Internet...
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