mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Fix to the way crop rects are rounded
Eight and bottom were previously rounded down which sometimes led to images having a width/height of 0 This fixes a ZeroDivisionError and potential "tile cannot extend outside image" errors when resizing JPEGs
This commit is contained in:
parent
4901f5dbf8
commit
217e9628c7
@ -1,6 +1,7 @@
|
||||
from __future__ import division
|
||||
|
||||
import inspect
|
||||
import math
|
||||
|
||||
from wagtail.wagtailimages.exceptions import InvalidFilterSpecError
|
||||
|
||||
@ -158,7 +159,7 @@ class FillOperation(Operation):
|
||||
bottom = image_height
|
||||
|
||||
# Crop!
|
||||
willow.crop((int(left), int(top), int(right), int(bottom)))
|
||||
willow.crop((math.floor(left), math.floor(top), math.ceil(right), math.ceil(bottom)))
|
||||
|
||||
# Get scale for resizing
|
||||
# The scale should be the same for both the horizontal and
|
||||
|
@ -154,7 +154,7 @@ class TestFillOperation(ImageOperationTestCase):
|
||||
# Basic usage with an oddly-sized original image
|
||||
# This checks for a rounding precision issue (#968)
|
||||
('fill-200x200', Image(width=539, height=720), [
|
||||
('crop', ((0, 90, 539, 629), ), {}),
|
||||
('crop', ((0, 90, 539, 630), ), {}),
|
||||
('resize', ((200, 200), ), {}),
|
||||
]),
|
||||
|
||||
@ -258,7 +258,32 @@ class TestFillOperation(ImageOperationTestCase):
|
||||
), [
|
||||
# This operation could probably be optimised out
|
||||
('crop', ((0, 0, 1500, 1500), ), {}),
|
||||
])
|
||||
]),
|
||||
|
||||
|
||||
# A few tests for single pixel images
|
||||
|
||||
('fill-100x100', Image(
|
||||
width=1,
|
||||
height=1,
|
||||
), [
|
||||
('crop', ((0, 0, 1, 1), ), {}),
|
||||
]),
|
||||
|
||||
# This one once gave a ZeroDivisionError
|
||||
('fill-100x150', Image(
|
||||
width=1,
|
||||
height=1,
|
||||
), [
|
||||
('crop', ((0, 0, 1, 1), ), {}),
|
||||
]),
|
||||
|
||||
('fill-150x100', Image(
|
||||
width=1,
|
||||
height=1,
|
||||
), [
|
||||
('crop', ((0, 0, 1, 1), ), {}),
|
||||
]),
|
||||
]
|
||||
|
||||
TestFillOperation.setup_test_methods()
|
||||
|
Loading…
Reference in New Issue
Block a user