Original address: http://www.jbxue.com/article/php/20251.html
Phpthumb several basic parameters
Some useful parameters are listed below:
SRC: Address of the target image
W: the width of the output picture
H: The height of the output image (if not specified he will be scaled by the W parameter, etc.)
Q: If the output is in JPG format, you can specify its output quality
BG: Background When output (if required)
SW, SH, SX, SY: Local output, wide height, starting position
F: Output format, can be JPEG, PNG, GIF, ICO
SFN: Output A frame in an animated GIF
Fltr[]: Filters, can have a lot of effects, including sharpening, Blur, spin flip, watermark, border, matte, color adjustment, etc.
More results can be found in the official routines:
Use Phpthumb and. htaccess to cache thumbnails
Principle: Users access/thumbs/images/image.50x50.jpg such URLs, scripts generate/images/image.jpg thumbnails, and save to/ Thumbs/images/image.50x50.jpg, the next visit will not need to tune PHP.
Introduction
about a year ago, I met Phpthumb, an open-source project for scaling pictures. 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 is very large, it will not survive, because Apache wants to tune PHP for each picture request to parse the PHPTHUMB code. Although Phpthumb has its own cache, it still has to tune PHP to decide whether to read from the cache.
I've seen someone use mod_rewrite to redirect non-existent images to a script that can generate thumbnails to address performance issues:
You need:
Apache
mod_rewrite
PHP
These things usually have a virtual host, as for how to install it is not within the scope of this article.
OK, just tell me how to do it!
Upload phpthumb
Download phpthumb from here:, upload it to/phpthumb
Configure mod_rewrite
New/thumbs/.htaccess:
<mod_rewrite.c></ifmodule>
New Thumbnail generation script:
New/thumbs/index.php
$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/phpthumb.class.php '); $phpThumb=NewPhpthumb ();$phpThumb->setsourcefilename ($image); $phpThumb->setparameter (' W ',$width); $phpThumb->setparameter (' H ',$height); //$phpThumb->setparameter (' Far ', ' C ');//scale outside//$phpThumb->setparameter (' bg ', ' <span class= ' caps ">FFFFFF</SPAN>"); Scale outsideif($phpThumb-Generatethumbnail ()) { mkdir(dirname($thumb), 0777,true); if($phpThumb->rendertofile ($thumb)) { Header(' Location:/thumbs/'.$thumb); Exit; } } }
Test method:
Upload an image to/images/myimage.jpg
Open your browser and visit/thumbs/images/myimage.100x100.jpg
Check the thumbs directory, there should be a thumbnail on that. The next visit will not need to tune PHP.
Articles you may be interested in:
- PHP image processing Class Phpthumb parameter usage detailed
- Phpthumb Image Processing Example parsing
- PHP image processing Class Phpthumb parameter usage introduction