markup: support rectangle and circle annotations

This commit is contained in:
2020-02-28 17:15:22 -08:00
parent dc85d784ab
commit b625b4f16d
2 changed files with 53 additions and 5 deletions

View File

@ -9,6 +9,8 @@ import dumper
import random as rng
from pathlib import Path
from pdfminer.psparser import LIT
from .utils import cv2_rect, ensure_dir, set_file_perms, WORKDIR
# https://www.pyimagesearch.com/2014/10/20/finding-shapes-images-using-python-opencv/
@ -112,10 +114,10 @@ def write_debug_image(workdir, page_num, prods, scribbles):
set_file_perms(path)
def write_inklist(obj, path):
def write_inklist(obj, mediabox, path):
"""Draw an image of the inklist."""
pagew = int(11*72)
pageh = int(8.5*72)
pagew = mediabox[2] - mediabox[0]
pageh = mediabox[3] - mediabox[1]
img = Image.new('RGBA', (pagew, pageh), (0, 0, 0, 0))
draw = ImageDraw.Draw(img, 'RGBA')
@ -129,3 +131,24 @@ def write_inklist(obj, path):
img.save(path)
set_file_perms(path)
def write_square_or_circle(obj, mediabox, path):
"""Draw an image of the inklist."""
pagew = mediabox[2] - mediabox[0]
pageh = mediabox[3] - mediabox[1]
img = Image.new('RGBA', (pagew, pageh), (0, 0, 0, 0))
draw = ImageDraw.Draw(img, 'RGBA')
if obj["Subtype"] == LIT('Square'):
draw.rectangle(obj['Rect'], fill=None, outline='black', width=3)
else:
draw.ellipse(*obj['Rect'], fill=None, outline='black', width=3)
# account for the difference in coordinate systems
# between pdf and images.
img = img.transpose(Image.FLIP_TOP_BOTTOM)
img.save(path)
set_file_perms(path)