PHPThumb image processing instance _ PHP Tutorial

Source: Internet
Author: User
Tags php website
PHPThumb image processing instance. (Github. commasterexploderPHPThumb ). Note that this class library is named phpThumb with the same name as it is case-sensitive, so pay attention to it when searching documents. In the network (github.com/masterexploder/PHPThumb ).
Note that this class library is named phpThumb with the same name as it is case-sensitive, so pay attention to it when searching documents.
In the process of website construction, there are a huge number of images to be processed. it is very tedious to use the PHP image function to process images. It is very difficult for new users to master. Now we can use the PHPThumb class library to process images, including image size adjustment, image capturing, Image watermarking, and image rotation.

Demo:

The code is as follows:


// Load the class library file
Require_once 'path/to/ThumbLib. inc. php ';

// Instantiate the class library. the address of the image you want to process can be a network address or a local address.
$ Thumb = PhpThumbFactory: create ('http: // www.jb51.net /');

// Scale down the image to a maximum width of PX or a maximum of px. when only one parameter is input, the maximum width is limited.
$ Thumb-> resize (100,100 );

// Reduce the image proportional ratio to the original percentage. for example, 50 is the original 50%.
$ Thumb-> resizePercent (50 );

// Intercept a 175px * 175px Image. Note that this is the intercept. the excess part is directly cropped, not forcibly changed.
$ Thumb-> adaptiveResize (175,175 );

// Extract a PX * px image from the image center.
$ Thumb-> cropFromCenter (200,100 );

// The first two parameters are the coordinates X and Y in the upper-right corner of the image to be extracted. The following two parameters are the width and height of the image to be solved.
$ Thumb-> crop (100,100,300,200 );

// Reverse the image clockwise to 180 degrees
$ Thumb-> rotateImageNDegrees (180 );

// Save (generate) the image. you can save other formats. For more information, see.
$ Thumb-> save ('newpath/Of/image.jpg ');

There are more functions in this class library. if you need to process images when developing a PHP website, read the documentation of this class library to ensure that you can process images easily, you no longer have to deal with the dozens of annoying php image processing functions!


Another powerful PHP image thumbnail class: phpThumb

In addition to scaling images, this class can also convert images into different formats for output (for example, exporting GIF images to PNG formats). its special features include colors and special effects.
Official website: http://phpthumb.sourceforge.net/

Generally, you only need the following files:
[Code] We'll be using phpThumb, the open source PHP script to generate thumbnails on the fly.
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

Adjust the path to phpThumb according to where you place the phpThumb files.






[Code]

In fact, phpThumb is more powerful than I previously imagined. below I will list some other useful parameters:
Src: Address of the target image
W: width of the output image
H: height of the output image (if not specified, the image will be scaled by the equal ratio of w parameter)
Q: If the output is in JPG format, you can specify the output quality.
Bg: Background of the output (if needed)
Sw, sh, sx, sy: local output, width and height, starting position
F: output format, which can be jpeg, png, gif, or ico.
Sfn: outputs a frame in the GIF animation.
Fltr []: filters can have many effects, including sharpening, Blur, rotation, watermark, border, masking, and color adjustment.

Http://www.bkjia.com/PHPjc/764625.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/764625.htmlTechArticle (github.com/masterexploder/PHPThumb ). Note that this class library is named phpThumb with the same name as it is case-sensitive, so pay attention to it when searching documents. In the network...

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.