PHP image processing Class Phpthumb parameter usage introduction _php tutorial

Source: Internet
Author: User
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:
http://phpthumb.sourceforge.net/demo/demo/phpThumb.demo.demo.php
Use Phpthumb and. htaccess to cache thumbnails
Principle: The user accesses the URL such as your.com/thumbs/images/image.50x50.jpg, the script generates your.com/images/image.jpg thumbnail, and saves to your.com/thumbs/ Images/image.50x50.jpg, the next visit will not need to tune PHP.
Brief introduction
About a year ago, I met Phpthumb, the bull's script, an open-source project to scale images. Of course you can use GD2 or ImageMagick (Magickwand) to do the same thing, but Phpthumb is dedicated to doing this. It is fairly simple to use:

If the traffic is very large, it will not survive, because Apache to each picture request to tune PHP to parse 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 to:
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:http://phpthumb.sourceforge.net/from here and upload it to Yoursite.com/phpthumb
Configure Mod_rewrite
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
Copy CodeThe 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/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 visit yoursite.com/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.
Official website http://phpthumb.gxdlabs.com/

http://www.bkjia.com/PHPjc/325252.html www.bkjia.com true http://www.bkjia.com/PHPjc/325252.html techarticle Phpthumb Several basic parameters some useful parameters are listed: src: The address of the target image w: the width of the output picture h: The height of the output picture (if not specified he will press the W parameter, etc. )

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.