markup: handle netpbm encoded annotations

This commit is contained in:
2019-12-04 17:02:21 -08:00
parent ae5e95a36a
commit aa2a6bc4ca
2 changed files with 68 additions and 6 deletions

View File

@ -20,12 +20,16 @@ def find_shapes(image_path):
"""
path = Path(image_path)
img = Image.open(image_path, 'r')
if not img.mode in ('RGBA', 'LA'):
print('no alpha channel: {}'.format(img.mode))
return None
print('finding shapes in {}'.format(image_path))
alpha_layer = img.convert('RGBA').split()[-1]
img = Image.open(image_path, 'r')
if img.mode == 'RGBA':
alpha_layer = img.convert('RGBA').split()[-1]
elif img.mode == 'L':
alpha_layer = img
else:
print('unhandled image mode: {}'.format(img.mode))
return None
alpha_layer = alpha_layer.filter(ImageFilter.GaussianBlur(5))