Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes #12472 Archetypes ImageField converts GIF to PNG when it scales

  • Loading branch information...
commit d4aa225d2b7588cb8b91ea11099971731a84c729 1 parent b45b2a9
Anthony Gerrard authored
View
8 Products/Archetypes/Field.py
@@ -2459,21 +2459,21 @@ def scale(self, data, w, h, default_format = 'PNG'):
# for palletted-only image formats, e.g. GIF
# PNG compression is OK for RGBA thumbnails
original_mode = image.mode
+ img_format = image.format and image.format or default_format
if original_mode == '1':
image = image.convert('L')
elif original_mode == 'P':
image = image.convert('RGBA')
image.thumbnail(size, self.pil_resize_algo)
- format = image.format and image.format or default_format
# decided to only preserve palletted mode
# for GIF, could also use image.format in ('GIF','PNG')
- if original_mode == 'P' and format == 'GIF':
+ if original_mode == 'P' and img_format == 'GIF':
image = image.convert('P')
thumbnail_file = StringIO()
# quality parameter doesn't affect lossless formats
- image.save(thumbnail_file, format, quality=self.pil_quality)
+ image.save(thumbnail_file, img_format, quality=self.pil_quality)
thumbnail_file.seek(0)
- return thumbnail_file, format.lower()
+ return thumbnail_file, img_format.lower()
security.declareProtected(permissions.View, 'getSize')
def getSize(self, instance, scale=None):
View
4 Products/Archetypes/HISTORY.txt
@@ -8,6 +8,10 @@
- use ISO8601() instead of ISO() for date metadata
[tom_gross]
+- Archetypes ImageField converts GIF to PNG when it scales
+ see http://dev.plone.org/plone/ticket/12472
+ [anthonygerrard]
+
1.5.19 - 2011-11-14
===================
View
15 Products/Archetypes/tests/test_fields.py
@@ -27,6 +27,10 @@
import os
+import PIL
+
+from StringIO import StringIO
+
from zope.interface import implements
from zope.component import getSiteManager
from zope.schema.interfaces import IVocabularyFactory
@@ -211,6 +215,17 @@ def test_image_tag(self):
self.assertEquals(image_field.tag(dummy, alt='', title=''),
'<img src="%s/dummy/imagefield" alt="" title="" height="16" width="16" />' % portal_name)
+ def test_gif_format_preserved_when_scaling(self):
+ dummy = self.makeDummy()
+
+ image_field = dummy.getField('imagefield')
+
+ scaled_image_file, img_format = image_field.scale(img_content, 5, 5)
+ self.assertEqual("gif", img_format)
+
+ image = PIL.Image.open(scaled_image_file)
+ self.assertEqual("GIF", image.format)
+
def test_get_size(self):
dummy = self.makeDummy()
request = FakeRequest()
Please sign in to comment.
Something went wrong with that request. Please try again.