PHP image processing Class Phpthumb parameter (GO)

Source: Internet
Author: User
Tags explode

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

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.