PHP image processing phpThumb parameter usage introduction. Several basic parameters of phpThumb. some useful parameters are listed below: src: Address of the target image w: width of the output image h: height of the output image (if this parameter is not specified, it will be reduced by the proportional ratio of the parameter w ).
PhpThumb basic parameters
Some useful parameters are listed below:
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.
For more results, see official routines:
Http://phpthumb.sourceforge.net/demo/demo/phpThumb.demo.demo.php
Use phpThumb and. htaccess to cache thumbnails
Principle: you can access a URL such as your.com/thumbs/images/image.5020.50.jpg, generate a thumbnail of your.com/images/image.jpg, and save it to php5.
Introduction
About a year ago, I met phpThumb, an open-source project for scaling images. Of course you can use GD2 or imagemagick (magickwand) to do the same thing, but phpThumb is dedicated to doing this. It is quite simple to use:
If the traffic volume is large, it will be unable to support it, because apache needs to call PHP for every image request to parse the phpThumb code. Although phpThumb has its own cache, it still needs to call PHP to determine whether to read from the cache.
I once saw someone using mod_rewrite to redirect a nonexistent image to a script that can generate a thumbnail to solve the performance problem:
You need:
Apache
Mod_rewrite
PHP
These items are usually available on virtual hosts. As for how to install them, they are not covered in this article.
OK. tell me how to get it!
Upload phpThumb
Download phpThumb: http://phpthumb.sourceforge.net/from here and upload it to yoursite.com/phpthumb
Configure Mod_Rewrite
Create yoursite.com/thumbs/.htaccess:
RewriteEngine on
RewriteCond % {REQUEST_FILENAME }! -F
RewriteCond % {REQUEST_FILENAME }! -D
RewriteRule ^ (. *) $ index. php? Thumb = $1 [L, QSA]
Script for creating a thumbnail:
Create yoursite.com/thumbs/index.php
The code is as follows:
$ Thumb = $ _ GET ['thumb'];
If (! $ Thumb ){
Exit;
}
//
$ Thumb_array = explode ('.', $ thumb );
$ Image = '../';
Foreach ($ thumb_array as $ k => $ thumb_part ){
If ($ k! = Count ($ thumb_array)-2 ){
$ Image. = $ thumb_part .'.';
}
}
$ Image = substr ($ image, 0,-1 );
List ($ width, $ height) = explode ('X', $ thumb_array [count ($ thumb_array)-2]);
//
If (file_exists ($ image )){
Require ('../phpthumb. class. php ');
$ PhpThumb = new phpThumb ();
$ PhpThumb-> setSourceFilename ($ image );
$ PhpThumb-> setParameter ('W', $ width );
$ PhpThumb-> setParameter ('H', $ height );
// $ PhpThumb-> setParameter ('far ', 'C'); // scale outside
// $ PhpThumb-> setParameter ('bg ','FFFFFF'); // Scale outside
If ($ phpThumb-> GenerateThumbnail ()){
Mkdir (dirname ($ thumb), 0777, true );
If ($ phpThumb-> RenderToFile ($ thumb )){
Header ('Location:/thumbs/'. $ thumb );
Exit;
}
}
}
Test it!
Upload an image to yoursite.com/images/myimage.jpg
Open your browser and access yoursite.com/thumbs/images/myimage.10020.100.jpg.
Check the thumbs Directory. There should be a thumbnail there. You don't need to call PHP for the next visit.
Official website http://phpthumb.gxdlabs.com/
Some useful parameters are listed as follows: src: the address of the target image w: the width of the output image h: the height of the output image (if not specified, it will be reduced by the ratio of the w parameter...