Fix rounding errors when resizing 1x1 images (backport 217e9628c7 to 0.8.x)

stable/0.8.x
Matt Westcott 2015-09-09 17:15:38 +01:00
rodzic dde242716c
commit 5a63a0b74a
3 zmienionych plików z 29 dodań i 3 usunięć

Wyświetl plik

@ -1,5 +1,7 @@
from __future__ import division
import math
from django.conf import settings
from wagtail.wagtailimages.rect import Rect
@ -242,7 +244,9 @@ class BaseImageBackend(object):
bottom = im_height
# Crop!
return self.resize_to_min(self.crop(image, Rect(left, top, right, bottom)), size)
return self.resize_to_min(self.crop(image,
Rect(math.floor(left), math.floor(top), math.ceil(right), math.ceil(bottom))
), size)
def no_operation(self, image, param, focal_point=None):
"""Return the image unchanged"""

Wyświetl plik

@ -164,6 +164,28 @@ class TestRenditions(TestCase):
self.assertEqual(first_rendition, second_rendition)
class TestSinglePixelRenditions(TestCase):
def setUp(self):
# Create an image for running tests on
self.image = Image.objects.create(
title="Test image",
file=get_test_image_file(width=1, height=1),
)
def test_resize(self):
rendition = self.image.get_rendition('fill-100x100')
self.assertEqual(rendition.width, 1)
self.assertEqual(rendition.height, 1)
rendition = self.image.get_rendition('fill-100x150')
self.assertEqual(rendition.width, 1)
self.assertEqual(rendition.height, 1)
rendition = self.image.get_rendition('fill-150x100')
self.assertEqual(rendition.width, 1)
self.assertEqual(rendition.height, 1)
class TestRenditionsWand(TestCase):
def setUp(self):
try:

Wyświetl plik

@ -9,8 +9,8 @@ from wagtail.wagtailimages.models import get_image_model
Image = get_image_model()
def get_test_image_file(filename='test.png'):
def get_test_image_file(filename='test.png', width=640, height=480):
f = BytesIO()
image = PIL.Image.new('RGB', (640, 480), 'white')
image = PIL.Image.new('RGB', (width, height), 'white')
image.save(f, 'PNG')
return ImageFile(f, name=filename)