mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-23 19:44:13 +03:00
Merge pull request #267 from chrispbailey/master
Better fix for ZeroDivisionError in ImageOps.fit for image.size height is 1
This commit is contained in:
commit
1f3c9f4feb
|
@ -275,10 +275,6 @@ def fit(image, size, method=Image.NEAREST, bleed=0.0, centering=(0.5, 0.5)):
|
||||||
# kevin@cazabon.com
|
# kevin@cazabon.com
|
||||||
# http://www.cazabon.com
|
# http://www.cazabon.com
|
||||||
|
|
||||||
# No cropping/fit possible. Prevents ZeroDivisionError @ liveAreaAspectRatio
|
|
||||||
if image.size == (1,1):
|
|
||||||
return image
|
|
||||||
|
|
||||||
# ensure inputs are valid
|
# ensure inputs are valid
|
||||||
if not isinstance(centering, list):
|
if not isinstance(centering, list):
|
||||||
centering = [centering[0], centering[1]]
|
centering = [centering[0], centering[1]]
|
||||||
|
@ -300,10 +296,12 @@ def fit(image, size, method=Image.NEAREST, bleed=0.0, centering=(0.5, 0.5)):
|
||||||
int((float(bleed) * float(image.size[1])) + 0.5)
|
int((float(bleed) * float(image.size[1])) + 0.5)
|
||||||
)
|
)
|
||||||
|
|
||||||
liveArea = (
|
liveArea = (0, 0, image.size[0], image.size[1])
|
||||||
bleedPixels[0], bleedPixels[1], image.size[0] - bleedPixels[0] - 1,
|
if bleed > 0.0:
|
||||||
image.size[1] - bleedPixels[1] - 1
|
liveArea = (
|
||||||
)
|
bleedPixels[0], bleedPixels[1], image.size[0] - bleedPixels[0] - 1,
|
||||||
|
image.size[1] - bleedPixels[1] - 1
|
||||||
|
)
|
||||||
|
|
||||||
liveSize = (liveArea[2] - liveArea[0], liveArea[3] - liveArea[1])
|
liveSize = (liveArea[2] - liveArea[0], liveArea[3] - liveArea[1])
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,6 @@ def test_sanity():
|
||||||
|
|
||||||
ImageOps.fit(lena("L"), (128, 128))
|
ImageOps.fit(lena("L"), (128, 128))
|
||||||
ImageOps.fit(lena("RGB"), (128, 128))
|
ImageOps.fit(lena("RGB"), (128, 128))
|
||||||
ImageOps.fit(lena("RGB").resize((1,1)), (35,35))
|
|
||||||
|
|
||||||
ImageOps.flip(lena("L"))
|
ImageOps.flip(lena("L"))
|
||||||
ImageOps.flip(lena("RGB"))
|
ImageOps.flip(lena("RGB"))
|
||||||
|
@ -59,6 +58,17 @@ def test_sanity():
|
||||||
|
|
||||||
success()
|
success()
|
||||||
|
|
||||||
|
def test_1pxfit():
|
||||||
|
# Division by zero in equalize if image is 1 pixel high
|
||||||
|
newimg = ImageOps.fit(lena("RGB").resize((1,1)), (35,35))
|
||||||
|
assert_equal(newimg.size,(35,35))
|
||||||
|
|
||||||
|
newimg = ImageOps.fit(lena("RGB").resize((1,100)), (35,35))
|
||||||
|
assert_equal(newimg.size,(35,35))
|
||||||
|
|
||||||
|
newimg = ImageOps.fit(lena("RGB").resize((100,1)), (35,35))
|
||||||
|
assert_equal(newimg.size,(35,35))
|
||||||
|
|
||||||
def test_pil163():
|
def test_pil163():
|
||||||
# Division by zero in equalize if < 255 pixels in image (@PIL163)
|
# Division by zero in equalize if < 255 pixels in image (@PIL163)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user