kopia lustrzana https://github.com/wagtail/wagtail
Fix rounding errors when resizing 1x1 images (backport 217e9628c7
to 0.8.x)
rodzic
dde242716c
commit
5a63a0b74a
|
@ -1,5 +1,7 @@
|
||||||
from __future__ import division
|
from __future__ import division
|
||||||
|
|
||||||
|
import math
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from wagtail.wagtailimages.rect import Rect
|
from wagtail.wagtailimages.rect import Rect
|
||||||
|
@ -242,7 +244,9 @@ class BaseImageBackend(object):
|
||||||
bottom = im_height
|
bottom = im_height
|
||||||
|
|
||||||
# Crop!
|
# 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):
|
def no_operation(self, image, param, focal_point=None):
|
||||||
"""Return the image unchanged"""
|
"""Return the image unchanged"""
|
||||||
|
|
|
@ -164,6 +164,28 @@ class TestRenditions(TestCase):
|
||||||
self.assertEqual(first_rendition, second_rendition)
|
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):
|
class TestRenditionsWand(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -9,8 +9,8 @@ from wagtail.wagtailimages.models import get_image_model
|
||||||
Image = 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()
|
f = BytesIO()
|
||||||
image = PIL.Image.new('RGB', (640, 480), 'white')
|
image = PIL.Image.new('RGB', (width, height), 'white')
|
||||||
image.save(f, 'PNG')
|
image.save(f, 'PNG')
|
||||||
return ImageFile(f, name=filename)
|
return ImageFile(f, name=filename)
|
||||||
|
|
Ładowanie…
Reference in New Issue