Fix badge image conversion issues

This fixes the problem where if you try to create a badge with a PNG
image that has an alpha channel, django-badger takes that alpha channel
out back and shoots it in the face with fire changing it to charcoal
black.
This commit is contained in:
Will Kahn-Greene 2013-09-11 10:00:23 -04:00
Родитель b74fbc3a03
Коммит 270895fa44
1 изменённых файлов: 4 добавлений и 1 удалений

Просмотреть файл

@ -158,7 +158,10 @@ def scale_image(img_upload, img_max_size):
x_offset + int(crop_width), y_offset + int(crop_height)))
img = img.resize((dst_width, dst_height), Image.ANTIALIAS)
if img.mode != "RGB":
# If the mode isn't RGB or RGBA we convert it. If it's not one
# of those modes, then we don't know what the alpha channel should
# be so we convert it to "RGB".
if img.mode not in ("RGB", "RGBA"):
img = img.convert("RGB")
new_img = StringIO()
img.save(new_img, "PNG")