PHP picture processing Class Phpthumb parameter usage introduction _php skill

Source: Internet
Author: User
Tags explode
phpthumb several basic parameters
Some useful parameters are listed:
SRC: Address of the target picture
W: the width of the output picture
H: The height of the output picture (if not specified he will be scaled by the W parameter ratio)
Q: If the output is in JPG format, it can specify its output quality
BG: Background When output (if required)
SW, SH, SX, sy: Partial output, wide and high, starting position
F: Output format, can be JPEG, PNG, GIF, ICO
SFN: Output A frame in a GIF animation
Fltr[]: Filters, can have many effects, including sharpening, Blur, spin flip, watermark, border, shading, color adjustment, etc.
More effects can be reviewed in official routines:
http://phpthumb.sourceforge.net/demo/demo/phpThumb.demo.demo.php
Use Phpthumb and. htaccess to cache thumbnails
Principle: Users visit URLs such as your.com/thumbs/images/image.50x50.jpg, the script generates your.com/images/image.jpg thumbnails, and saves them to the your.com/thumbs/ Images/image.50x50.jpg, the next visit will not have to tune PHP.
Brief introduction
About a year ago I came across a script that phpthumb this cow, which is an open source project for scaling pictures. Of course you can use GD2 or ImageMagick (Magickwand) to do the same thing, but Phpthumb do it specifically. It's pretty simple to use:

If the traffic is very large, it will not hold up, because Apache to the request for each picture to tune PHP to parse the PHPTHUMB code. Although Phpthumb has its own cache, it still has to tune PHP to determine whether to read from the cache.
I've seen someone use mod_rewrite to redirect a nonexistent picture to a script that can generate thumbnails to solve a performance problem:
You need to:
Apache
Mod_rewrite
Php
These things usually have a virtual host, as to how the installation is not within the scope of this article.
OK, just 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
New yoursite.com/thumbs/.htaccess:
<ifmodule mod_rewrite.c>
Rewriteengine on
Rewritecond%{request_filename}!-f
Rewritecond%{request_filename}!-d
Rewriterule ^ (. *) $ index.php?thumb=$1 [L,QSA]
</IfModule>
New Thumbnail generation script:
New yoursite.com/thumbs/index.php
Copy Code code 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 ', ' <span class=caps>ffffff</span> '); Scale outside
if ($phpThumb->generatethumbnail ()) {
mkdir (DirName ($thumb), 0777,true);
if ($phpThumb->rendertofile ($thumb)) {
Header (' Location:/thumbs/'. $thumb);
Exit
}
}
}

Test it!
Upload a picture to yoursite.com/images/myimage.jpg
Open your browser and access the Yoursite.com/thumbs/images/myimage.100x100.jpg
Check the thumbs directory, there should be a thumbnail over there. The next visit will not have to tune PHP.
Official website http://phpthumb.gxdlabs.com/

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.