Phpthumb PHP picture thumbnail gallery _php Tips

Source: Internet
Author: User
1, this is a thumbnail class library
It is an open source picture thumbnail class Library, can complete a variety of complex picture thumbnail generation and reality, very convenient to use.

2, the use of methods
Here is a simple and practical explanation, the English is relatively simple, will not translate:

Basic-usage

3, API
Here is a list of APIs:

Phpthumb API

But unfortunately, the API does not have any explanation, can only compare its English name to guess its effect, of course, even if the right, but also test to see if it is correct.

4. Sample Example
I also wrote a simple way to call it here, but I saved the picture as a file, and the examples in Basic-usage were all printed directly on the page:
Copy Code code as follows:

Require_once ' phpthumb/thumblib.inc.php ';
try {
$thumb = Phpthumbfactory::create ($realpath);
catch (Exception $e) {
Handle error here However your ' d like
}
$thumb->adaptiveresize ($width, $height);
$thumb->save ($realpath. '.' . $width. ' X '. $height. '. png ');

5, I used a few APIs
In the process of using, the understanding of several APIs deepens, here is recorded:

Resize ($maxWidth, $maxHeight)

The Resize method is the most commonly used thumbnail method, which reduces the maximum edge to the required height/width directly, and there is an edge display blank when the picture is not as wide or as high as the requirement.

Adaptiveresize ($width, $height)

The adaptiveresize approach is to require that the picture be complete without requiring the maximum number of specific widths to be displayed in certain situations. The specific calculation method is:

When the picture width is greater than the required width, and the height is consistent, take the height, the width required from the middle of the picture;
When the height of the picture is large and the width is the same, go to the width, the picture up and down center position to obtain the desired height;
When the width is not correct, the picture is scaled to the required size, and then the first two is executed.
Save ($fileName, $format = ' gif| Jpg| PNG ')

When you are done with a picture, you can use the Save method to save the picture as one of the encodings indicated in format, and if no encoding is specified, it is saved in the original encoding. $fileName is the path you want to save.

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.