only use alpha channel if it exists

This commit is contained in:
Thomas Rehn 2014-10-09 18:05:09 +02:00
parent 8a9027edd1
commit 93dc416dd3
1 changed files with 6 additions and 1 deletions

View File

@ -438,7 +438,12 @@ class Escpos:
f.seek(0)
img_rgba = Image.open(f)
img = Image.new('RGB', img_rgba.size, (255,255,255))
img.paste(img_rgba, mask=img_rgba.split()[3])
channels = img_rgba.split()
kwargs = {}
if len(channels) > 1:
# use alpha channel as mask
kwargs['mask'] = img_rgba.split()[3]
img.paste(img_rgba, **kwargs)
print 'convert image'