News
2006-07-30 * A PHP4-release of version 2.0 is now available
Due to the fact that most webhosts are slow in adopting and upgrading to the latest versions of the software running on their servers (such as PHP!) I've thrown together a package of PHPImageMage version 2.0 that works with PHP4 (which the PHP5-version doesn't). You'll find it available for download on SourceForge.net.
2006-07-12 * Version 2.0 is released
As of this version this is no longer a webapplication as such, but rather an API implemented in the form of a PHP5-class. This class encapsulates all (or most at the present..) of the functionality available in the previous versions and makes this functionality easily available to other projects.
About
PHPImageMage is a PHP5-class that acts as an API and simplifies many of the things most commonly done to images in webapplications. It handles JPG, PNG and GIF images and requires PHP5 with GD-support.
The current version of PHPImageMage is 2.0.
And yes, I know the name is a bit retarded but it's too late to change it now ;-P
Download
To get the latest version of PHPImageMage, pop over to SourceForge.net and download it.
Documentation
To use PHPImageMage you must first create an instance of the class and feed an imagefile to the constructor. Like this:
//This file comes from an upload-form
$file=$_FILES['uploaded_file']['tmp_name'];
$pim=new PHPImageMage($file);
Once you have an instance of the PHPImageMage-class at your disposal and an image wrapped up in it, you can start performing the various methods on it. For example, to resize an image and add a caption to it you'd do something like this:
//Change image-dimension to 360x240 without keeping the aspect ratio
$pim->resizeImage(360, 240, FALSE);
//Add the text "My caption" in the color white at position (0, 0)
$pim->overlayWithText(0, 0, "My caption", 255, 255, 255);
$pim->saveImageToFile("pictures/some_pic.jpg");
Or directly to the browser:
$pim->outputImage();
Methods:
__construct($imagefile)
The constructor is the method called when the class is instantiated. It creates the object's image from the file $imagefile.
setImage($imagefile)
Changes the image contained in the PHPImageMage-object into $imagefile. This is actually the method called by the constructor of the class when it is first instantiated.
outputImage()
Writes the image directly to the browser.
saveImageToFile($filename)
Writes the image to the file $filename.
resizeImage($x, $y, $keep_aspect_ratio)
Resizes the image to size width=$x and height=$y. If $keep_aspect_ratio is set to TRUE the scale of the image will be kept intact even if the values of $x and $y say otherwise. The smallest value of the both will be used as a guide when resizing. $keep_aspect_ratio defaults to FALSE.
getImageX()
Returns the width of the image.
getImageY()
Returns the height of the image.
overlayWithImage($x, $y, $overlayimage)
Overlays the image with another image at position ($x, $y). The image $overlayimage must be a PNG-image.
overlayWithText($x, $y, $text, $R, $G, $B)
Overlays the image with text at position ($x, $y). The color of the text will be ($R, $G, $B). Bright red for example is (255, 0, 0) and bright green is (0, 255, 0). The color defaults to white.
rotateImage($degrees, $R, $G, $B)
Rotates the image counter clockwise and fills the exposed background with color ($R, $G, $B). The background-color defaults to white.
setThumbnail($x, $y, $keep_aspect_ratio)
Creates a thumbnail for the image and sets it to size width=$x and height=$y. If $keep_aspect_ratio is set to TRUE the scale of the thumbnail will be kept intact even if the values of $x and $y say otherwise. The smallest value of the both will be used as a guide when resizing. $keep_aspect_ratio defaults to FALSE.
outputThumbnail()
Writes the thumbnail directly to the browser.
saveThumbnailToFile($filename)
Writes the thumbnail to the file $filename.