torchbox/wagtail — pull request #139 by spapas (2014-03-12 07:10:51+00:00)
Title: Add support for image proecssing backends and add Wand/ImageMagick backend

A refactoring of image processing code has been done, moving the image processing code to the wagtailimages/backends package and changing models.py (more specifically, the process_image method of Filter model) to use the code there. If the image contains a backend attribute the backend to be used will be selected based on that attribute.

The backends package contains the __init__.py module which defines the get_image_backend method that will get the correct image backend based on the passed parameter (or default if not parameter is passed) and the WAGTAILIMAGES_BACKENDS option. The code is copied with small modifications from similar code in wagtailsearch/backends package (TODO: this needs to be moved to a util package for DRY-ness)

Concerning the backends, a BaseImageBackend is defined in the base module. This interface defines a number of methods that the backends inheriting from it should implement. The only methods that need to be implemented is open_image, save_image, resize and crop_to_centre. The other methods are inherited from the parent (if the image object provides a size and format attribute).

The two backends, wand_backend and pillow_backend provide implementations for Pillow and Wand.

To be able to use Wand, we have to install Wand + ImageMagick. Follow the instructions here: http://docs.wand-py.org/en/0.3.5/guide/install.html. Also, since as a default the pillow backend will be used, if we want to use wand we have to set

``
WAGTAILIMAGES_BACKENDS = {
'default': {
'BACKEND': 'wagtail.wagtailimages.backends.wand_backend.WandBackend',
},
}
``

in our settings.py.

Tests have been modified to test both image backends (pillow + wand).

Finally, this PR contains code to fix #136: Use the unidecode library to convert Unidecode image filenames to their ascii equivalent. Please notice that you have to install unidecode to your project (setup.py of wagtail has already been changed to also include Unidecode).