From 280000d6eda6c6c7aa5721cb79d0a92a5e16c203 Mon Sep 17 00:00:00 2001 From: Manuel F Martinez Date: Sat, 22 Aug 2015 12:43:09 -0700 Subject: [PATCH] Fixed issues with transparent images --- CHANGELOG | 13 +++++++++++++ escpos/escpos.py | 11 ++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index d137f7e..05cc9da 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -22,3 +22,16 @@ CHANGELOG - Added charcode tables - Fixed Horizontal Tab - Fixed code tabulators + +* 2015-04-21 - Version 1.0.5 +- Merge pull request #45 from Krispy2009/master + . Raising the right error when wrong charcode is used + . Sent by Krispy2009@gmail.com + +* 2015-07-06 - Version 1.0.6 +- Merge pull request #53 from ldos/master + . Extended params for serial printers + . Sent by cafeteria.ldosalzira@gmail.com + +* 2015-08-22 - Version 1.0.6 +- Issue #57: Fixed transparent images diff --git a/escpos/escpos.py b/escpos/escpos.py index b2e91f7..2263458 100644 --- a/escpos/escpos.py +++ b/escpos/escpos.py @@ -107,7 +107,15 @@ class Escpos: def image(self,path_img): """ Open image file """ im_open = Image.open(path_img) - im = im_open.convert("RGB") + + # Remove the alpha channel on transparent images + if im_open.mode == 'RGBA': + im_open.load() + im = Image.new("RGB", im_open.size, (255, 255, 255)) + im.paste(im_open, mask=im_open.split()[3]) + else: + im = im_open.convert("RGB") + # Convert the RGB image in printable image self._convert_image(im) @@ -119,6 +127,7 @@ class Escpos: qr_code.make(fit=True) qr_img = qr_code.make_image() im = qr_img._img.convert("RGB") + # Convert the RGB image in printable image self._convert_image(im)