From ae8a3b8ef8e66b8c5cee9f49406b376bda99a575 Mon Sep 17 00:00:00 2001 From: iu_long Date: Sat, 5 Nov 2011 18:25:17 +0200 Subject: [PATCH] RGBA is a transparent image mode too . When saving RGBA, you cannot specify 'transparency' color - you get IOError wrong mode. --- imagekit/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/imagekit/utils.py b/imagekit/utils.py index b6ca548..c41a06e 100644 --- a/imagekit/utils.py +++ b/imagekit/utils.py @@ -11,8 +11,9 @@ def img_to_fobj(img, format, **kwargs): # Preserve transparency if the image is in Pallette (P) mode. transparency_formats = ('PNG', 'GIF', ) - if img.mode == 'P' and format in transparency_formats: - kwargs['transparency'] = len(img.split()[-1].getcolors()) + if format in transparency_formats: + if img.mode == 'P': + kwargs['transparency'] = len(img.split()[-1].getcolors()) else: img = img.convert('RGB')