[Checkins] SVN: z3c.image/trunk/ - taking care of allowed image size. That means the resulting iamge size

Bernd Roessl bernd.roessl at lovelysystems.com
Mon Feb 4 19:19:50 EST 2008


Log message for revision 83515:
  - taking care of allowed image size. That means the resulting iamge size
    will get calculated
  
  

Changed:
  U   z3c.image/trunk/CHANGES.txt
  U   z3c.image/trunk/src/z3c/image/proc/BROWSER.txt
  U   z3c.image/trunk/src/z3c/image/proc/browser.py

-=-
Modified: z3c.image/trunk/CHANGES.txt
===================================================================
--- z3c.image/trunk/CHANGES.txt	2008-02-04 20:10:28 UTC (rev 83514)
+++ z3c.image/trunk/CHANGES.txt	2008-02-05 00:19:50 UTC (rev 83515)
@@ -2,6 +2,13 @@
 Changes for z3c.image
 =====================
 
+2008/02/05 0.1.6:
+=================
+
+- taking care of allowed image size. That means the resulting iamge size
+  will get calculated
+
+
 2008/01/17 0.1.5:
 =================
 

Modified: z3c.image/trunk/src/z3c/image/proc/BROWSER.txt
===================================================================
--- z3c.image/trunk/src/z3c/image/proc/BROWSER.txt	2008-02-04 20:10:28 UTC (rev 83514)
+++ z3c.image/trunk/src/z3c/image/proc/BROWSER.txt	2008-02-05 00:19:50 UTC (rev 83515)
@@ -91,6 +91,21 @@
    >>> getImageInfo(browser.contents)
    ('image/jpeg', 5, 5)
 
+Crop top left 40x20px out of the image and resize it to 10x20xpx. This means
+the ratio of the crop does not match the ratio of the desired size so the best
+ratio will be taken::
+
+   >>> browser.open('http://localhost/flower.jpg/@@processed?' +
+   ...     'local.crop.h=20&' +
+   ...     'local.crop.w=40&' +
+   ...     'local.crop.x=0&' +
+   ...     'local.crop.y=0&' +
+   ...     'after.size.h=20&' +
+   ...     'after.size.w=10&'
+   ...     )
+   >>> getImageInfo(browser.contents)
+   ('image/jpeg', 10, 5)
+
 It is also possible to omit one dimension of afterSize to keep the resulting
 ratio of the image. If the image get cropped the resulting ratio will be
 apointed by the crop.::

Modified: z3c.image/trunk/src/z3c/image/proc/browser.py
===================================================================
--- z3c.image/trunk/src/z3c/image/proc/browser.py	2008-02-04 20:10:28 UTC (rev 83514)
+++ z3c.image/trunk/src/z3c/image/proc/browser.py	2008-02-05 00:19:50 UTC (rev 83515)
@@ -78,6 +78,19 @@
             ratio = float(w) / float(h)
         return ratio
 
+    @property
+    def _resultingSize(self):
+        if (    self.cropW is not None
+            and self.cropH is not None
+            and self.cropW != 0
+            and self.cropH != 0
+           ):
+            return (int(self.cropW), int(self.cropH))
+        else:
+            context = removeSecurityProxy(self.context)
+            t,w,h = getImageInfo(context.data)
+            return (int(w), int(h))
+
     def _calcAfterSize(self):
         if (self.afterSizeW == 0 or self.afterSizeH == 0) and \
            self.afterSizeW != self.afterSizeH:
@@ -106,7 +119,8 @@
                              int(self.cropY) + int(self.cropH))
             pimg.crop(self.croparea)
         if self.afterSizeW is not 0 and self.afterSizeH is not 0:
-            pimg.resize(self.afterSize)
+            size = getMaxSize(self._resultingSize, self.afterSize)
+            pimg.resize(size)
         return pimg.process()
 
     def processed(self):



More information about the Checkins mailing list