Gregphoto_Image Overview

THE BASICS

Overview

Gregphoto_Image is a PHP class that aims to simplify the process of generating thumbnail images in the JPEG, PNG, and GIF formats. Images can either be rendered directly to the screen or saved to the filesystem.

Prerequisites

Features

License

This class is licensed under the MIT license. Do with it what you will...

Getting it

Gregphoto_Image is available on Google Code in the Gregphoto_Image Project

SAMPLE USAGE

Rendering thumbnails to the browser

In this example, a file is loaded from the file system and is resized to a maximum height of 100 and a maximum width of 150 with a quality of 90 (out of 100_. It is then rendered to the browser:
require('path/to/Gregphoto_Image.php');
$image = new Gregphoto_Image('path/to/sample/image.jpg');
$image->setMaxHeight(200);
$image->setMaxWidth(200);
$image->setJpegQuality(90);
$image->resize(Gregphoto_Image::BEST_FIT);
$image->showThumbnail();

Saving thumbnails to the filesystem and setting the output file type

The following shows the same manipulation, but instead it is saved to a file and it is output in a different image format. The output type can be one of the following three constants: IMAGETYPE_JPEG, IMAGETYPE_GIF, or IMAGETYPE_PNG
require('path/to/Gregphoto_Image.php');
$image = new Gregphoto_Image('path/to/image.jpg');
$image->setMaxHeight(200);
$image->setMaxWidth(200);
$image->setJpegQuality(90);
$image->setOutputType(IMAGETYPE_PNG);
$image->resize(Gregphoto_Image::BEST_FIT);
$image->saveThumbnail('path/to/thumbnail.png');

More Examples

See the 'samples' directory of the distribution for more examples including: