PHP image processing phpThumb parameter usage introduction. For more information, see 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
$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 = 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.
For more information about the usage of PHP image processing phpThumb parameters, refer to the PHP Chinese website!