1. This is a thumbnail class library
It is an open source picture thumbnail class library that can complete a variety of complex picture thumbnail generation and reality, and is very convenient to use.
2. Usage
Here is a simple and practical explanation about it. The English is relatively simple and will not be translated:
Basic-Usage
3. API
Here is a list of APIs:
PHPThumb API
But it is a pity that there is no explanation in the API, you can only compare it Guess the effect of the English name. Of course, even if you guess it correctly, you still need to test it to see if it is correct.
4. Example
Here I also wrote a simple method to call it, but I saved the image as a file. The examples in basic-usage are all Output directly on the page:
Copy code The code is as follows:
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 APIs I used During the use process, my understanding of several APIs gradually deepened. I will record them here:
resize ( $maxWidth, $maxHeight)
The resize method is the most commonly used thumbnail method. It directly reduces the largest side to the required height/width in equal proportions. When the image aspect ratio is inconsistent with the requirements, the There will be blank edges.
adaptiveResize ($width, $height)
The adaptiveResize method does not require the completeness of the image in some specific cases, but requires that the maximum content of a specific width and height be displayed. The specific calculation method is:
When the width of the picture is greater than the required width and the height is the same, take the height and go from the middle of the left and right sides of the picture to the required width;
When the height of the picture is larger and When the width is the same, go to the width and center the top and bottom of the image to obtain the required height;
When the width and height are incorrect, first scale the image to the required size, and then execute the first two steps.
save ($fileName, $format = 'GIF|JPG|PNG')
After the image is processed, you can use the save method to save the image as one of the codes indicated in format , if no encoding is specified, it will be saved in the original encoding. $fileName is the path to save.
http://www.bkjia.com/PHPjc/325255.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325255.htmlTechArticle1. This is a thumbnail class library. It is an open source picture thumbnail class library that can complete a variety of tasks. Complex image thumbnail generation and reality are very convenient to use. 2. How to use...