Author: jmorliaguet
Date: Sun Nov  6 22:10:38 2005
New Revision: 29025

Modified:
   
z3lab/cpsskins/branches/jmo-perspectives/engines/default/filters/effect/__init__.py
   z3lab/cpsskins/branches/jmo-perspectives/engines/default/formats/effect.py
Log:

- added patch by Olivier to preserve the image ratio while scaling images



Modified: 
z3lab/cpsskins/branches/jmo-perspectives/engines/default/filters/effect/__init__.py
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/engines/default/filters/effect/__init__.py
 (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/engines/default/filters/effect/__init__.py
 Sun Nov  6 22:10:38 2005
@@ -61,6 +61,14 @@
             return data
 
         new_size = (context.width, context.height)
+        if context.keep_ratio:
+            # updating new_size to keep constant ratio
+            w, h = Image(StringIO(element.data)).getImageSize()
+            if w and h:
+                z_w = int(context.width) / float(w)
+                z_h = int(context.height) / float(h)
+                zoom = min(z_w, z_h)
+                new_size = (int(zoom * w), int(zoom * h))
         tmutil = getThemeManager()
         cache = tmutil.getImageCache()
         key = {

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/engines/default/formats/effect.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/engines/default/formats/effect.py  
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/engines/default/formats/effect.py  
Sun Nov  6 22:10:38 2005
@@ -20,7 +20,7 @@
 from persistent import Persistent
 from zope.interface import implements
 from zope.i18nmessageid import MessageFactory
-from zope.schema import Choice, Int
+from zope.schema import Choice, Int, Bool
 
 from cpsskins.elements.format import Format
 from cpsskins.elements.interfaces import IFormat
@@ -54,16 +54,25 @@
         min=0,
         required=False)
 
+    keep_ratio = Bool(
+        title=_("Keep ratio"),
+        description=_("If this option is enabled, the image will be scaled"
+                      " to a box of maximum size (Width x Heigth)."),
+        default=True,
+        required=False)
+
 class Effect(Format, Persistent):
     """Image processing effect.
     """
     implements(IEffect)
 
-    def __init__(self, id='', format='PNG', width=0, height=0):
+    def __init__(self, id='', format='PNG', width=0, height=0,
+                 keep_ratio=True):
         Format.__init__(self, id=id)
         self.format = format
         self.width = width
         self.height = height
+        self.keep_ratio = keep_ratio
 
     def __repr__(self):
         return "Effect('%s')" % self.getEffectId()
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to