Skip to content

Commit

Permalink
Fix image reader for transparent PNG
Browse files Browse the repository at this point in the history
  • Loading branch information
tsurumeso committed Nov 6, 2018
1 parent 9bb635d commit 035832c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/iproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,19 @@ def y2rgb(src):


def read_image_rgb_uint8(path):
src = Image.open(path).convert('RGB')
dst = np.array(src, dtype=np.uint8)
src = Image.open(path)
if src.mode in ('L', 'RGB', 'P'):
if isinstance(src.info.get('transparency'), bytes):
src = src.convert('RGBA')
mode = src.mode
if mode in ('LA', 'RGBA'):
if mode == 'LA':
src = src.convert('RGBA')
rgb = Image.new('RGB', src.size, (128, 128, 128))
rgb.paste(src, mask=src.split()[-1])
else:
rgb = src.convert('RGB')
dst = np.array(rgb, dtype=np.uint8)
return dst


Expand Down

0 comments on commit 035832c

Please sign in to comment.