Skip to content

Commit

Permalink
ENH: Add alpha channel support for png files (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedali-zorgati1997 committed Apr 6, 2022
1 parent 7528347 commit 90d5539
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Scripts/pdf-image-extractor.py
Expand Up @@ -34,6 +34,9 @@
if '/Filter' in xObject[obj]:
if xObject[obj]['/Filter'] == '/FlateDecode':
img = Image.frombytes(mode, size, data)
if "/SMask" in xObject[obj]: # add alpha channel
alpha = Image.frombytes("L", size, xObject[obj]["/SMask"].getData())
img.putalpha(alpha)
img.save(obj[1:] + ".png")
elif xObject[obj]['/Filter'] == '/DCTDecode':
img = open(obj[1:] + ".jpg", "wb")
Expand Down

0 comments on commit 90d5539

Please sign in to comment.