zero negative crop values (resulting from mark overlapping frame border)
authorMarcin Koziej <marcin@lolownia.org>
Tue, 17 Dec 2013 09:35:12 +0000 (10:35 +0100)
committerMarcin Koziej <marcin@lolownia.org>
Tue, 17 Dec 2013 09:35:12 +0000 (10:35 +0100)
apps/picture/templatetags/picture_tags.py

index 38e7a66..826f6aa 100644 (file)
@@ -45,24 +45,24 @@ def area_thumbnail_url(area, geometry):
                     [coords[1][0] - w/2 + h/2, coords[1][1]]]
         else:
             return [[coords[0][0], coords[0][1] + h/2 - w/2],
                     [coords[1][0] - w/2 + h/2, coords[1][1]]]
         else:
             return [[coords[0][0], coords[0][1] + h/2 - w/2],
-                    [coords[1][0], coords[1][1] - h/2 + w/2, ]]            
+                    [coords[1][0], coords[1][1] - h/2 + w/2, ]]
 
 
-    # so much for sorl extensibility. 
-    # what to do about this?
+    # so much for sorl extensibility.                                                                                                                           # what to do about this?                                                                                                                                 
     _engine = sorl.thumbnail.default.engine
     sorl.thumbnail.default.engine = cropper
     coords = to_square(area.area)
     _engine = sorl.thumbnail.default.engine
     sorl.thumbnail.default.engine = cropper
     coords = to_square(area.area)
-    logging.debug("coords: %s, %s" % (unicode(coords), geometry))
+
     try:
         th = sorl.thumbnail.default.backend.get_thumbnail(
             area.picture.image_file,
             geometry,
     try:
         th = sorl.thumbnail.default.backend.get_thumbnail(
             area.picture.image_file,
             geometry,
-            crop="%dpx %dpx %dpx %dpx" % tuple(coords[0] + coords[1]))
+            crop="%dpx %dpx %dpx %dpx" % tuple(map(lambda d: max(0, d), tuple(coords[0] + coords[1]))))
     except Exception, e:
         logging.exception("Error creating a thumbnail for PictureArea")
     except Exception, e:
         logging.exception("Error creating a thumbnail for PictureArea")
+        return ''
 
     sorl.thumbnail.default.engine = _engine
 
     sorl.thumbnail.default.engine = _engine
-    
+
     return th.url
             
 
     return th.url