PHPThumbPHP image thumbnail library _ PHP Tutorial

Source: Internet
Author: User
PHPThumbPHP image thumbnail library. 1. this is a thumbnail class library. it is an open-source image thumbnail class library that can be used to generate and implement various complex image thumbnails. 2. usage 1. this is a thumbnail class library.
It is an open-source image thumbnail library that can be used to generate and implement various complex image thumbnails.

2. usage
Here is a simple and practical description about it. The English is relatively simple and will not be translated:

Basic-Usage

3. API
Here is a list of APIs:

PHPThumb API

However, it is a pity that there is no explanation in the API, and you can only guess the effect based on the English name. of course, even if you guessed it right, you should test whether 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:

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 use
During usage, the understanding of several APIs is gradually deepened. here we record:

Resize ($ maxWidth, $ maxHeight)

The resize method is the most commonly used thumbnail method, which directly scales down the maximum side to the required height/width. when the aspect ratio of the image is different from the requirement, the edges are blank.

AdaptiveResize ($ width, $ height)

The adaptiveResize method is used to display the largest content with a specified width and height, but does not require Image integrity in certain situations. The calculation method is as follows:

When the image width is greater than the required width and the height is the same, take the width required from the middle of the image to the bottom of the height;
When the image height is large and the width is the same, go to the width and the image is centered up and down to obtain the required height;
When the width and height are incorrect, first scale the image to the required size, and then follow the first two steps.
Save ($ fileName, $ format = 'gif | JPG | PNG ')

After processing the image, you can use the save method to save the image as one of the encoding indicated in the format. If no encoding is specified, it will be saved as the original encoding. $ FileName is the path to save.

It is an open-source image thumbnail library that can be used to generate a variety of complex image thumbnails and make it easy to use. 2. usage...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.