Home >Backend Development >PHP Tutorial >PHPThumb image processing example_PHP tutorial
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:
//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.