From c9faa9caa5bee7983970e383773635bf73534980 Mon Sep 17 00:00:00 2001 From: Peter van Kampen Date: Sun, 23 Jun 2013 12:33:23 +0200 Subject: [PATCH 1/2] Fix for ZeroDivisionError in ImageOps.fit for image.size == (1,1) --- PIL/ImageOps.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/PIL/ImageOps.py b/PIL/ImageOps.py index 835572f7d..ddba8ba1f 100644 --- a/PIL/ImageOps.py +++ b/PIL/ImageOps.py @@ -274,6 +274,10 @@ def fit(image, size, method=Image.NEAREST, bleed=0.0, centering=(0.5, 0.5)): # kevin@cazabon.com # http://www.cazabon.com + # No cropping/fit possible + if image.size == (1,1): + return image + # ensure inputs are valid if not isinstance(centering, list): centering = [centering[0], centering[1]] From ad0a96c3fa2d09c2fe896182bb37c3b7a3cfd353 Mon Sep 17 00:00:00 2001 From: Peter van Kampen Date: Sun, 23 Jun 2013 15:22:31 +0200 Subject: [PATCH 2/2] add test & comment --- PIL/ImageOps.py | 2 +- Tests/test_imageops.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/PIL/ImageOps.py b/PIL/ImageOps.py index ddba8ba1f..e9badff37 100644 --- a/PIL/ImageOps.py +++ b/PIL/ImageOps.py @@ -274,7 +274,7 @@ def fit(image, size, method=Image.NEAREST, bleed=0.0, centering=(0.5, 0.5)): # kevin@cazabon.com # http://www.cazabon.com - # No cropping/fit possible + # No cropping/fit possible. Prevents ZeroDivisionError @ liveAreaAspectRatio if image.size == (1,1): return image diff --git a/Tests/test_imageops.py b/Tests/test_imageops.py index 362937e81..5ef7f257a 100644 --- a/Tests/test_imageops.py +++ b/Tests/test_imageops.py @@ -37,6 +37,7 @@ def test_sanity(): ImageOps.fit(lena("L"), (128, 128)) ImageOps.fit(lena("RGB"), (128, 128)) + ImageOps.fit(lena("RGB").resize((1,1)), (35,35)) ImageOps.flip(lena("L")) ImageOps.flip(lena("RGB"))