PHPThumb PHP image thumbnail library

  • 2020-05-16 06:29:57
  • OfStack

1. This is a thumbnail class library
It is an open source image thumbnail class library, can complete a variety of complex image thumbnail generation and reality, use is very convenient.

2. Method of use
Here is a simple and practical explanation, which is not translated since it is relatively simple in English:

Basic-Usage

3, API
Here is a list of API:

PHPThumb API

Unfortunately, API doesn't have any instructions. You can only guess its effect against its English name, but even if you get it right, you have to test it to see if it's correct.

4, sample
Here I also wrote a simple way to call it, but I saved the image as a file, and the examples in basic-usage are all printed directly on the page:
 
require_once 'phpthumb/ThumbLib.inc.php'; 
try { 
$thumb = PhpThumbFactory::create($realpath); 
} catch (Exception $e) { 
// handle error here however you'd like 
} 
$thumb->adaptiveResize($width, $height); 
$thumb->save($realpath . '.' . $width . 'x' . $height . '.png'); 

5. Several API I used
During the use of API, my understanding of several API gradually deepened. Here is the record:

resize ($maxWidth, $maxHeight)

resize method is the most commonly used thumbnail method, which directly equalizes the maximum edge to the required height/width. When the image aspect ratio is different from the requirement, there will be blank edges.

adaptiveResize ($width, $height)

The adaptiveResize method does not require the image to be complete in certain situations, but to display the maximum content of a given width and height. The specific calculation method is as follows:

When the width of the picture is larger than the required width, and the height is 1, take the height, from the left to the middle of the picture to the required width;
When the height of the picture is large and the width is 1, go to the width, the top and bottom center position of the picture to obtain the required height;
When both the width and height are incorrect, scale the image to the desired size and press the first two.
save ($fileName, $format = 'GIF|JPG|PNG')

When the image has been processed, you can use the save method to save the image as 1 of the code indicated in format. If no code is specified, the image will be saved as the original code. $fileName is the path to save.

Related articles: