Created
January 10, 2019 03:22
-
-
Save mkroutikov/85cea837338749c7bd12be2f6d79aded to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_overlay(imagename, box, outname): | |
'''creates a PNG image of base with overlayed colored boxes. Useful for human review''' | |
if 'size' not in box: | |
return | |
img = Image.open(imagename).convert('RGB') | |
draw = ImageDraw.Draw(img, 'RGBA') | |
for key,color in [ | |
('title', (255, 0, 0, 128)), | |
('authors', (0, 255, 0, 128)), | |
('abstract', (0, 0, 255, 128)) | |
]: | |
bbox = box.get(key) | |
if bbox: | |
draw.rectangle(bbox, fill=color) | |
del draw | |
img.save(outname, 'PNG') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment