Demo:
The code is as follows: |
Copy code |
// 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.111cn.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 ); // Screenshot. 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/
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
The code is as follows: |
Copy code |
Adjust the path to phpThumb according to where you place the phpThumb files. <Html> <Head> </Head> <Body>
</Body> </Html>
|
Generally, you only need the following files.
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.