Home > Backend Development > PHP Tutorial > PHPThumb image processing example analysis

PHPThumb image processing example analysis

WBOY
Release: 2016-07-25 09:13:07
Original
959 people have browsed it

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. There are countless places to process images, and it is very cumbersome to use PHP's image functions to process images. And it is very difficult for novices to master. You can use the PHPThumb class library to process images, including image resizing, image interception, image watermarking, image rotation and other functions.

Example:

  1. //Load the class library file
  2. require_once 'path/to/ThumbLib.inc.php';
  3. //Instantiate the class library, and pass in the address of the image you want to process. Network address, or local address
  4. $thumb = PhpThumbFactory::create('http://bbs.it-home.org/');
  5. //Reduce the image to a maximum width of 100px or a maximum of 100px, when When only one parameter is entered, the widest size is limited.
  6. $thumb->resize(100, 100);
  7. //Reduce the image to the original percentage, for example, 50 is 50% of the original.
  8. $thumb->resizePercent(50);
  9. //Intercept a 175px * 175px image. Note that this is an interception, and the excess part is directly cropped, not forced to change the size.
  10. $thumb->adaptiveResize(175, 175);
  11. //Calculate from the center of the image, intercept the 200px * 100px image.
  12. $thumb->cropFromCenter(200, 100);
  13. //Screenshot, the first two parameters are the coordinates X and Y of the upper right corner of the picture to be solved. The last two parameters are the width and height of the image that need to be solved.
  14. $thumb->crop(100, 100, 300, 200);
  15. //Reverse the image 180 degrees clockwise
  16. $thumb->rotateImageNDegrees(180);
  17. //Save (generate) the image, you can Save other formats, please refer to the document for details
  18. $thumb->save( 'NewPath/Of/image.jpg ' );
Copy the code

This class library has more functions, which I won’t introduce 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 easy for you to process images, and you no longer have to deal with those dozen annoying PHP image processing functions!

Another powerful PHP image thumbnail class: phpThumb In addition to scaling pictures, this class can also convert pictures into different formats for output (such as outputting pictures in GIF format to PNG format). Its special functions also include color, special effects, etc. Official website: http://phpthumb.sourceforge.net/ Generally, you only need the following files:

  1. We'll be using phpThumb , the open source PHP script to generate thumbnails on the fly.
  2. 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
  3. Adjust the path to phpThumb according to where you place the phpThumb files.
Copy code

In fact, phpThumb has more functions than me I originally thought it would be more powerful. Let’s list some of its other useful parameters:

src: the address of the target image w: width of the output image h: the height of the output image (if not specified, it will be scaled according to the w parameter) q: If the output is in JPG format, you can specify its output quality. bg: background when output (if needed) sw, sh, sx, sy: local output, width, height, starting position f: Output format, which 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, border, masking, color adjustment, etc.


source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template