Craig Francis


PHP Image

From doing several sites which require simple image manipulation, I have created a simple image object as a wrapper for the GD library.

See below for some examples of what it can do - each one is a link to the source code which generated it.

There is also the "saveTiles" function... its purpose is to take one big image, and save many smaller images to a folder (fileNamePrefix), which can be used with the "Giant Scalable Image Viewer" (demo).

If you think this script might be useful, you can download a copy of the source code, which contains instructions at the beginning on how to use it.

Uploads

It might also be worth looking at my form object, as this image object was also written to work with users uploading images to galleries.

Field setup:

$form = new form();

$fldImage = new formFieldImage($form, 'Image');
$fldImage->setMaxSize('The image file cannot be bigger than XXX.', 1048576); // 1MB
$fldImage->setUnrecognisedFileType('The image file has an unrecognised file type.');
$fldImage->setRequiredError('The image is required.');

Image processing:

$image = new image($fldImage->getFilePath());
$image->centerToBox(200, 200); // Force image size
$image->addImage('frame.png'); // Add a frame overlay
$image->saveImageJpg($urlThumb); // Create thumbnail

$fldImage->saveFileTo($urlFull); // Moves the image

Any feedback would be greatly appreciated. If you would like to use this code, please read the licence it is released under.