[Image-SIG] PIL thumbnail zero division patch

Gene Skonicki gene at siteworx.com
Fri Feb 4 00:03:26 CET 2005


 
Greetings,
 
The (very) short patch below corrects some issues I have had in PIL
using the thumbnail method in certain, admittedly pathological
conditions.  When aspect ratios are large enough and one dimension is
small enough, it is possible to get these lines to go to zero and pass
zeros through to draft().
 
I'm not an expert on the finer points of graphics processing, so this
may not be the most correct solution.
 
Regards,
Gene
 
--- Image.py.orig       Thu Feb  3 17:42:43 2005
+++ Image.py    Thu Feb  3 17:32:40 2005
@@ -1420,8 +1420,8 @@
 
         # preserve aspect ratio
         x, y = self.size
-        if x > size[0]: y = y * size[0] / x; x = size[0]
-        if y > size[1]: x = x * size[1] / y; y = size[1]
+        if x > size[0]: y = (y * size[0] / x) or 1; x = size[0]
+        if y > size[1]: x = (x * size[1] / y) or 1; y = size[1]
         size = x, y
 
         if size == self.size:

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/image-sig/attachments/20050203/84758e62/attachment.htm


More information about the Image-SIG mailing list