Home > Article > Backend Development > PHP image processing class phpThumb parameter usage introduction_PHP tutorial
Several basic parameters of phpThumb
List some useful parameters:
src: the address of the target image
w: the width of the output image
h: the height of the output image (if If not specified, it will be scaled according to the w parameter)
q: If the output is in JPG format, its output quality can be specified
bg: The background during output (if needed)
sw, sh, sx , sy: local output, width, height, starting position
f: output format, which can be jpeg, png, gif, ico
sfn: output a certain frame in the gif animation
fltr[]: filter Mirror can have many effects, including sharpening, blurring, rotation, watermark, border, masking, color adjustment, etc.
For more effects, please refer to the official routine:
http://phpthumb.sourceforge.net /demo/demo/phpThumb.demo.demo.php
Use phpThumb and .htaccess to cache thumbnails
Principle: The user visits a URL like your.com/thumbs/images/image.50×50.jpg, The script generates a thumbnail of your.com/images/image.jpg and saves it to your.com/thumbs/images/image.50×50.jpg. You don’t need to adjust PHP next time you visit.
Introduction
About a year ago I came across this awesome script called 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 designed for this. It is quite simple to use:
If the number of visits is large, it will not be able to sustain it, because apache It is necessary to adjust PHP to parse the phpThumb code for each image request. Even though phpThumb has its own cache, it still has to call PHP to decide whether to read from the cache.
I once saw someone use mod_rewrite to redirect non-existent images to a script that can generate thumbnails to solve performance problems:
You need:
Apache
mod_rewrite
PHP
These things are usually available on virtual hosts. How to install them is beyond the scope of this article.
OK, tell me how to do it!
Upload phpThumb
Download phpThumb from here: http://phpthumb.sourceforge.net/ and upload it to yoursite.com/phpthumb
Configure Mod_Rewrite
Create new yoursite.com/thumbs/.htaccess :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index. php?thumb=$1 [L,QSA]
New thumbnail generation script:
New yoursite.com/thumbs/index.php