Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes #12488 Animated GIF loses animation if Archetypes ImageField or…

…iginal_size property set

* don't attempt to scale animated GIF images if original image is no bigger than the scale requested
  • Loading branch information...
commit 48a766434ced6faa40fadd7888ed9bfcd5f30e81 1 parent 759e418
Anthony Gerrard authored
View
5 CHANGES.txt
@@ -4,8 +4,9 @@ Changelog
1.7.12 (unreleased)
-------------------
-- Nothing changed yet.
-
+- Animated GIF loses animation if Archetypes ImageField original_size property set
+ see http://dev.plone.org/ticket/12488
+ [anthonygerrard]
1.7.11 (2012-01-26)
-------------------
View
12 Products/Archetypes/Field.py
@@ -2489,6 +2489,18 @@ def scale(self, data, w, h, default_format = 'PNG'):
original_file=StringIO(data)
image = PIL.Image.open(original_file)
+
+ if image.format == 'GIF' and size[0] >= image.size[0] and size[1] >= image.size[1]:
+ try:
+ image.seek(image.tell() + 1)
+ # original image is animated GIF and no bigger than the scale requested
+ # don't attempt to scale as this will lose animation
+ original_file.seek(0)
+ return original_file, 'gif'
+ except EOFError:
+ # image is not animated
+ pass
+
# consider image mode when scaling
# source images can be mode '1','L,','P','RGB(A)'
# convert to greyscale or RGBA before scaling
View
14 Products/Archetypes/tests/test_fields.py
@@ -76,6 +76,8 @@
txt_content = txt_file.read()
img_file = open(os.path.join(PACKAGE_HOME, 'input', 'tool.gif'), 'rb')
img_content = img_file.read()
+animated_gif_file = open(os.path.join(PACKAGE_HOME, 'input', 'animated.gif'), 'rb')
+animated_gif_content = animated_gif_file.read()
field_values = {'objectfield':'objectfield',
'stringfield':'stringfield',
@@ -223,6 +225,18 @@ def test_gif_format_preserved_when_scaling(self):
image = PIL.Image.open(scaled_image_file)
self.assertEqual("GIF", image.format)
+ def test_dont_scale_animated_gif_when_original_is_smaller_than_scale_size(self):
+ dummy = self.makeDummy()
+
+ image_field = dummy.getField('imagefield')
+
+ scaled_image_file, img_format = image_field.scale(animated_gif_content, 100, 100)
+ self.assertEqual("gif", img_format)
+
+ image = PIL.Image.open(scaled_image_file)
+ self.assertEqual("GIF", image.format)
+ image.seek(image.tell() + 1)
+
def test_get_size(self):
dummy = self.makeDummy()
request = FakeRequest()
Please sign in to comment.
Something went wrong with that request. Please try again.