Plottable Thumbnail Library

Website - Changelog - Version 1.2.10

Contents


Introduction

Plottable Thumbnail Library is a class that allows you to generate thumbnails of images on the fly. It supports caching of thumbnails. In addition, the library can write the thumbnails generated to a file for you! The library can automatically calculate the dimensions of your thumbnail based on the following: The image formats currently supported are: [Return to top]

Requirements

The library requires the following components: In addition, the following optional components will add more features to the library: [Return to top]

Getting Started

Before you start, I assume you have knowledge of PHP and how to use PHP classes. You can find information on them for PHP 4 or PHP 5 at the PHP manual.

This section is about the use of your own code (and not the example). If you are interested in seeing the example usage directions, refer to the example section.

First off, you would need to include the class file into your script with something like:

require_once("Pthumb.php");

Initialise the class and set some variables if needed. You can find out more about the different configuration directives available in this section.

$pthumb = new Pthumb(); //Initialise the class
$pthumb -> use_cache = true; //Set to true to use cache
$pthumb -> cache_dir = "cache/"; //Cache DIR. Make sure to include trailing slash!

Call upon the various methods to start generating thumbnails!

$pthumb -> print_thumbnail("image.png", 200, 200);
$pthumb -> scale_thumbnail("image.png", 0.5);
$pthumb -> fit_thumbnail("image.png", 200, 200);
[Return to top]

Example Usage Instructions

The example is a full implementation of the class that is executed by HTTP GET Parameters. You can even use it directly for your thumbnail generating solutions!

Here is a run-down of the various parameters of the example script

Examples:

[Return to top]

Cache Information

[Return to top]

Configuration Directives

[Return to top]

Methods

Pthumb

void Pthumb ( void )

Class constructor. Checks to see if GD is enabled and returns an error as appropriate if error is encountered.


error

array error ( [bool is_fatal] )

Returns an array of errors. is_fatal defaults to true. If is_fatal is true, fatal errors are returned. Otherwise, warnings are returned.


fit_thumbnail

mixed fit_thumbnail ( str image, int max_width, int max_height [, int behaviour [, bool return]] )

Calculates the new dimensions of image such that it fits within the maximum width and height max_width and max_height respectively and preserving the width-height ratio of the image. behaviour defaults to 1. If set to 1, the dimensions with the bigger pixel area will be returned in the case of ambiguity. Otherwise, set to 2 to return the dimensions with smaller pixel area.

return defaults to false. If set to true, an array with the calculated dimensions will be returned. The first element is the width while the second is the height. Otherwise, a callback to print_thumbnail with the calculated dimensions is returned.


image_to_file

bool image_to_file ( str data, str filename [, bool overwrite])

Writes image data to filename and overwries any existing file if overwrite is set to true. The default value is false.


isError

bool isError ( void )

Returns true if an error has occured or false otherwise.


print_thumbnail

str print_thumbnail ( str image, int width, int height [, bool return [, bool display_inline]] )

Resizes image according to width and height. return is false by default. If set to true, thumbnail data is returned. Otherwise, thumbnail is directly outputted to the browser. If display_inline is true (by default), headers sent to browser will instruct browser to display the image inline. Otherwise, headers will be sent to the browser to display image as an attachment. For more information, refer to RFC 1806.


scale_thumbnail

mixed scale_thumbnail ( str image, float scale [, bool return] )

Calculates the new dimensions of image according to the scale specified. return defaults to false. If set to true, an array with the calculated dimensions will be returned. The first element is the width while the second is the height. Otherwise, a callback to print_thumbnail with the calculated dimensions is returned.

[Return to top]
Last Updated:
© 2004-2007 Chua Yong Wen [http://chuayw2000.6x.to] [lawliet89[at]gmail.com]