mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-25 17:30:23 +00:00
Fix conversion of PNG "palette" or "P" mode images to JPEG.
"P" mode images need to be converted to 'RGB' if target image format is not PNG or GIF.
This commit is contained in:
parent
5985def06b
commit
d36e624acb
1 changed files with 3 additions and 2 deletions
|
|
@ -10,10 +10,11 @@ def img_to_fobj(img, format, **kwargs):
|
|||
tmp = tempfile.TemporaryFile()
|
||||
|
||||
# Preserve transparency if the image is in Pallette (P) mode.
|
||||
if img.mode == 'P':
|
||||
transparency_formats = ('PNG', 'GIF', )
|
||||
if img.mode == 'P' and format in transparency_formats:
|
||||
kwargs['transparency'] = len(img.split()[-1].getcolors())
|
||||
else:
|
||||
img.convert('RGB')
|
||||
img = img.convert('RGB')
|
||||
|
||||
img.save(tmp, format, **kwargs)
|
||||
tmp.seek(0)
|
||||
|
|
|
|||
Loading…
Reference in a new issue