uploads: Convert CMYK to RGB when saving avatar/realm icon as png.

Fixes #8546.
PNG does not support CMYK mode. CMYK file is converted to RGB and
then saved as PNG.
This commit is contained in:
Shubham Padia 2018-03-02 22:26:25 +05:30 committed by Tim Abbott
parent 92ba40b0c7
commit 13664f1289
3 changed files with 6 additions and 2 deletions

View File

@ -88,6 +88,8 @@ def resize_avatar(image_data: bytes, size: int=DEFAULT_AVATAR_SIZE) -> bytes:
except IOError:
raise BadImageError("Could not decode image; did you upload an image file?")
out = io.BytesIO()
if im.mode == 'CMYK':
im = im.convert('RGB')
im.save(out, format='png')
return out.getvalue()

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

View File

@ -654,7 +654,8 @@ class AvatarTest(UploadSerializeMixin, ZulipTestCase):
('img.png', 'png_resized.png'),
('img.jpg', None), # jpeg resizing is platform-dependent
('img.gif', 'gif_resized.png'),
('img.tif', 'tif_resized.png')
('img.tif', 'tif_resized.png'),
('cmyk.jpg', None)
]
corrupt_files = ['text.txt', 'corrupt.png', 'corrupt.gif']
@ -821,7 +822,8 @@ class RealmIconTest(UploadSerializeMixin, ZulipTestCase):
('img.png', 'png_resized.png'),
('img.jpg', None), # jpeg resizing is platform-dependent
('img.gif', 'gif_resized.png'),
('img.tif', 'tif_resized.png')
('img.tif', 'tif_resized.png'),
('cmyk.jpg', None)
]
corrupt_files = ['text.txt', 'corrupt.png', 'corrupt.gif']