Hi everyone!
My job this summer is to create an image library for Joomla! developers, easy to use and with lots of functionalities. I will explain how to install and use JImageLib to process images, and I would be very thankful if you help me finding bugs and improving my work.
Prerequisites
To make JImageLib work with all the image processors available (GD, ImageMagick, GraphicsMagick) you must make sure these are installed on your server.
You can download for free and install ImageMagick from http://www.imagemagick.org/script/binary-releases.php, available for Unix, MacOS and Windows, and GraphicsMagick from http://www.graphicsmagick.org/download.html, available for both Linux and Windows operating systems.
Installing JImageLib
The library can be found on the SVN : http://labs.joomla.org/svn/labs/playground/people/daniel/trunk/libraries/ .
To install the library simply copy the JImageLib directory into your libraries/ directory. After the files are copied, please make sure you edit the config.php file and change the DEFAULT_IMAGE_MAGICK_DIRECTORY and DEFAULT_GRAPHICS_MAGICK_DIRECTORY to point to the directories where you installed ImageMagick and GraphicsMagick. Also, you can configure other defaults, such as DEFAULT_PREFIX for generated images, DEFAULT_DIRECTORY and so on. These are also configurable through the JImageLib class methods.
Including JImageLib
To include the library you must simply add the following line into your code:
jimport( 'JImageLib.JImageLib' );
Using the library
To use the library you just instantiate a JImageLib object and use the class public methods.
For example, you want to create a grayscale flipped thumbnail for the 'images/joomla_logo_black.jpg' image (350x71), let's say having the width=300, using ImageMagick image processing library, use a custom prefix for the generated image, a custom directory, use the image size both in the directory and filename. This is how it can be done:
- create the object and set the new width
$img = new JImageLib();
$img->setWidth(300);
- load the image to be processed
if (! $img->load('images/joomla_logo_black.jpg')){
print $img->getError();
print "< br / >";
}
if (! $img->setImageLib('im')){
print $img->getError();
print "< br / >";
}
- setting the grayscale filter and the flipping (vertical)
if (! $img->setFilter('grayscale')){
print $img->getError();
print "< br / >";
}
if (! $img->setFlipping('V')){
print $img->getError();
print "< br / >";
}
- customize naming
if (! $img->setDirectory('images/thumbs/')){
print $img->getError();
print "< br / >";
}
if (! $img->setUseImageSize('both')){
print $img->getError();
print "< br / >";
}
if (! $img->setPrefix('thumb_')){
print $img->getError();
print "< br / >";
}
- finally, generate the thumbnail
if (! $img->getThumbnail()){
print $img->getError();
print "< br / >";
}
- and that's it!
Next..
... I will create a content plugin that interprets a scripting language and uses the class methods to process images, for Joomla! administrators who are not that familiar with programming and I will update the last year GSoC Advanced Media Manager, also to make the library functionalities be more accessible.
I am waiting for any suggestions/questions/feedback you might have.
Thanks,
Daniel