Hello everybody,
our next module is an performant manipulator for Pageimages. It is called GIM.
GIM is basically a wrapper for the PHP library Gregwar's image class, which performs many image manipulations. The wrapper is written in a way that is compatible with Horst's PageImageManipulator's (PIM) syntax.
How does it work?
GIM extends ProcessWire's Pageimage objects. You can load every image with the method gim(), perform some operations and save the image with the save() method:
$image = $page->image->gim()->grayscale()->save();
The save() method returns another Pageimage object, so you can use it with other native ProcessWire methods and hooks.
Methods
GIM includes a lot of methods for image manipulations. You can find them in more detail on our module page.
You can crop, resize, flip and rotate the image in several ways
You can apply filters like sepia to the image
You can add texts and shapes to the image
You can merge multiple images in multiple ways
Compatibility with Horst's PageImageManipulator (PIM)
You can just use GIM instead of PIM by replacing pim with gim:
$image1 = $page->image->pimLoad('prefix')
->setOptions(array('outputFormat'=>'jpg'))
->brightness(-10)
->contrast(15)
->grayscale()
->width(600)
->pimSave(); // uses PageImageManipulator
$image2 = $page->image->gimLoad('prefix')
->setOptions(array('outputFormat'=>'jpg'))
->brightness(-10)
->contrast(15)
->grayscale()
->width(600)
->gimSave(); // uses GIM
GIM includes every method from PIM, so it just works. Also GIM and PIM share the same variation naming scheme, so when you start using GIM, the transition is seamless and does not need to recreate every image.
Having the same naming schemes means, that GIM and PIM can also work side-by-side.
For a full list of compatibility and migration notes, please check out our module page.
Performance
The reason why we created GIM is that we were looking for a more performant PHP image library for converting lots of images at once. After using Gregwar's image class for a few images, we thought that this library should find its way into ProcessWire.
After testing GIM on a few sites, this is what we found out:
GIM handles already manipulated images around 40% faster
GIM is able to heavily manipulate at least 15 large images (> 2000px) in one request (more weren't tested yet)
GIM is slightly faster than PIM for single image operations
I hope this is a great addition to the ProcessWire module ecosystem and you can enjoy it.
Thanks in advance,
Marvin
P.S.: Horst, I hope you don't see this as offense. PIM is a great module!