Permalink
Browse files

Filters should not be required to use thumbor. Fixes #138.

Filters should not be required to use thumbor. If filters have not been compiled properly and an user tries to use them, we should give meaningful messages saying that they are not available and direct the user to reinstall thumbor with the filters compiled properly.
  • Loading branch information...
1 parent cec8ed0 commit c4b30f88a8e18baf0ea4ea48fe1d59e9acd4eac3 @heynemann heynemann committed Dec 14, 2012
Showing with 40 additions and 2 deletions.
  1. +1 −1 test_requirements.txt
  2. +10 −1 thumbor/engines/pil.py
  3. +29 −0 vows/pil_engine_vows.py
View
2 test_requirements.txt
@@ -5,7 +5,7 @@ pillow>=1.7.5,<1.8.0
simplejson>=2.1.6,<2.2.0
pymongo==2.1.1
redis==2.4.9
-http://gevent.googlecode.com/files/gevent-1.0b2.tar.gz
+gevent
pyvows
tornado-pyvows
coverage
View
11 thumbor/engines/pil.py
@@ -19,7 +19,13 @@
from thumbor.engines import BaseEngine
from thumbor.engines.extensions.pil import GifWriter
from thumbor.utils import logger
-from thumbor.ext.filters import _composite
+
+try:
+ from thumbor.ext.filters import _composite
+ FILTERS_AVAILABLE = True
+except ImportError:
+ FILTERS_AVAILABLE = False
+
FORMATS = {
'.jpg': 'JPEG',
@@ -179,6 +185,9 @@ def convert_to_rgb(self):
return converted_image.mode, self.get_image_data(converted_image)
def paste(self, other_engine, pos, merge=True):
+ if merge and not FILTERS_AVAILABLE:
+ raise RuntimeError('You need filters enabled to use paste with merge. Please reinstall thumbor with proper compilation of its filters.')
+
self.enable_alpha()
other_engine.enable_alpha()
View
29 vows/pil_engine_vows.py
@@ -0,0 +1,29 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# thumbor imaging service
+# https://github.com/globocom/thumbor/wiki
+
+# Licensed under the MIT license:
+# http://www.opensource.org/licenses/mit-license
+# Copyright (c) 2011 globo.com timehome@corp.globo.com
+
+from pyvows import Vows, expect
+ctx = Vows.Context
+
+import thumbor.engines.pil as PIL
+
+@Vows.batch
+class PilEngineVows(ctx):
+
+ class ShouldRaiseIfFiltersNotAvailable(ctx):
+ def topic(self):
+ PIL.FILTERS_AVAILABLE = False
+ engine = PIL.Engine(None)
+ return engine.paste(None, None, True)
+
+ def should_be_an_error(self, topic):
+ expect(topic).to_be_an_error()
+ expect(topic).to_be_an_error_like(RuntimeError)
+ expect(topic).to_have_an_error_message_of('You need filters enabled to use paste with merge. Please reinstall thumbor with proper compilation of its filters.')
+

1 comment on commit c4b30f8

@suneel0101

👍 Thanks, this is great!

Please sign in to comment.