Recently, I’ve been contributing to Imagine a lot. Imagine is a PHP Image Processing library. It provide an OO abstract layer for processing image with the driver of your choice (Graphics Magick, ImageMagick or GD). The code is quite cool, you should have a look to it.
As I’m having heavy use of this library and was missing some features, I’ve dug the code and I’m now contributing a lot. One of the feature I’m currently working on is ExactImage support. Although ExactImage PHP bindings have been used in production at Skyrock, I didn’t know this lib before somebody asked for it on GitHub and it seems the internet does not know so much about it.
ExactImage is an opensource library developed in Germany by a R&D company focused on image/audio digital signal processing. It has an ImageMagick-like command line API and has been designed for speed.
“In the mid-2000s we were wondering about the ridiculous amounts of CPU cycles ImageMagick spent on certain image processing tasks. After the first code review it became clear that imagemagick was coded for anything but speed”
It uses Swig to generate binding for Perl, Lua, Ruby, Python, PHP. The PHP API is not documented online at all. That’s probably why it’s not used so much.
I’ve posted on GitHub a beginning of the ExactImage PHP API doc. Use it, fork it, share it ! It’s open source, man !
Bindings
Here are some examples of common image processing compared to Imagick API :
Image load
// ImageMagick
$imagick = new \Imagick();
$imagick->readImageFile(file_get_contents('image.jpg'));
// ExactImage
$image = newImage();
decodeImage($image, file_get_contents("image.jpg"));
Image crop
// ImageMagick
$imagick->cropImage($width, $height, $x, $y);
// ExactImage
imageCrop($image, $x, $y, $width, $height);
Resize
// ImageMagick
$imagick->resizeImage(320, 240,
\Imagick::FILTER_UNDEFINED, 1);
// ExactImage
imageResize($image,320, 240)
Rotation
// ImageMagick
$imagick->rotateimage(
new \ImagickPixel('fff'), 90);
// ExactImage
setbackgroundcolor(1.0, 1.0, 1.0, 1.0);
imageRotate($image, 90);
Save
// ImageMagick
$imagick->writeImage('modified-image.jpg');
// ExactImage
encodeImageFile($image, 'modified-image.jpg')
Be carefull
Swig provides the PHP extension, defining the same functions as in the original C library. When you call a PHP function, Swig looks for a match between the function you’re calling and its signature (ie the type of the parameters you passed) and the declared functions of ExactImage. For some functions, if you do not use exactly right types, it will result in a fatal error. For example, using setBackgroundColor with integer will produce :
PHP Fatal error: No matching function for overloaded
setBackgroundColor
setBackgroundColor MUST be used with float values :
void setBackgroundColor(float $red,
float $green, float $blue, float $alpha)
This is unusual in PHP, and I’ve spent some time fighting with the library before having realized that : )
Single drawback
One drawback to exactimage : It does not prefix its functions, and, as it declares functions with the same name as GD (imagerotate), you can not load both extensions at the same time.
More infos :
http://www.exactcode.com/site/open_source/exactimage/
http://www.perlmonks.org/?node_id=705531
Edit 1 :
See doxygen documentation http://fossies.org/dox/exact-image-0.8.7