MCPcopy Create free account
hub / github.com/SpaceZephyr/myskill / create_validation_image

Function create_validation_image

pdf/scripts/create_validation_image.py:11–30  ·  view source on GitHub ↗
(page_number, fields_json_path, input_path, output_path)

Source from the content-addressed store, hash-verified

9
10
11def create_validation_image(page_number, fields_json_path, input_path, output_path):
12 # Input file should be in the `fields.json` format described in forms.md.
13 with open(fields_json_path, 'r') as f:
14 data = json.load(f)
15
16 img = Image.open(input_path)
17 draw = ImageDraw.Draw(img)
18 num_boxes = 0
19
20 for field in data["form_fields"]:
21 if field["page_number"] == page_number:
22 entry_box = field['entry_bounding_box']
23 label_box = field['label_bounding_box']
24 # Draw red rectangle over entry bounding box and blue rectangle over the label.
25 draw.rectangle(entry_box, outline='red', width=2)
26 draw.rectangle(label_box, outline='blue', width=2)
27 num_boxes += 2
28
29 img.save(output_path)
30 print(f"Created validation image at {output_path} with {num_boxes} bounding boxes")
31
32
33if __name__ == "__main__":

Callers 1

Calls 1

saveMethod · 0.45

Tested by

no test coverage detected