 |
Web Gadget: Thumbnail
Description
This gadget is used to display photos and other images. It will resize an image on the fly and optionally add various decorations (drop shadows, borders, frames, etc.) that you specify.
Usage Summary
@include "gadget:thumbnail";
Details
To use this gadget you must first create a PHP file that contains your thumbnail configuration options. It should look
something like this:
<?
$CONFIG['size'] = "150";
$CONFIG['cache'] = "thumbnails";
$CONFIG['overlay1'] = "myframe.png";
@include "gadget:thumbnail";
?>
|
Note that you must first define any configuration options, then include the thumbnail gadget. This file should not output
anything (so watch for blank lines or extra characters outside of the <? and ?> tags!)
The available configuration options are:
- $CONFIG['size']
- This is the maximum height or width of the image (in pixels) that will be generated.
- $CONFIG['outline']
- This is a standard 6 character HTML color code. If set it causes a thin 1 pixel wide line to be drawn around the edge of the image.
- $CONFIG['border']
- If this value is set, it causes a solid color border to be added around the image. It must be either a plain number (which
indicates the width in pixels) or a number followed by a percent sign (which indicates a percentage of the generated image size).
- $CONFIG['paper']
- This is a standard 6 character HTML color code that controls the "paper" color. If you've specified a border, this is the color it will be. If your image has and transparent bits, this is the color that will show through.
- $CONFIG['background']
- This is a standard 6 character HTML color code that controls the background color. If you've applied a drop shadow effect, or an overlay with an irregular edge, this is the color that will show through.
- $CONFIG['shadow']
- This is the name of another image file that will be drawn first, underneath the main image. It is primarily used to add a drop shadow effect.
- $CONFIG['shadowx'] and $CONFIG['shadowy']
- These are numbers that control how far to the right and how far down the shadow image should be shifted. These can either be plain numbers (in which case they represent pixels) or numbers followed by a percent sign.
- $CONFIG['overlay1'] through to $CONFIG['overlay5']
- You can specify up to 5 overlay images. Each one (if set) will be drawn over top of the image. This is used primarily to add frames and borders.
- $CONFIG['cache']
- Generated images are cached to speed up subsequent accesses to the same image. If you leave this unset, the cached thumbnails will be stored in a location outside of your account where they won't contribute to your disk space. if you would prefer to cache them in your own area (where you can control how long they last before being deleted) set this to the name of a directory that exists.
One you have created your thumbnail PHP file you can use it to display images. Consider a web page that contains the following
image tag:
To have your thumbnail script display it instead you would change it to this:
<img src=thumb.php?image=photo1.jpg>
|
This will display the same image, but reformatted dynamically according to the settings you specified in your thumb.php file.
NOTE: you can only use the thumbnail gadget on images that exist in the same directory as your PHP file, or in a subdirectory below it. You cannot use it to display an URL.
Most configuration options can be overridden by adding them to the URL. For example, if most of the time you want to generate thumbnails that are no more than 150 pixels wide (or high), you would add $CONFIG['size'] = 150 to your PHP file. But if you want to override this and display a larger one you could do this:
<img src=thumb.php?image=photo1.jpg&size=500>
|
Example:
The "thumb.php" file: thumb.php
A PHP program that lets you view various images and select different thumbnail options: example.php
Try it out!
|  |