Skip to content

Instantly share code, notes, and snippets.

@mkroutikov
Created January 10, 2019 03:22
Show Gist options
  • Save mkroutikov/85cea837338749c7bd12be2f6d79aded to your computer and use it in GitHub Desktop.
Save mkroutikov/85cea837338749c7bd12be2f6d79aded to your computer and use it in GitHub Desktop.
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