Skip to content

Commit d369447

Browse files
authored
Merge pull request JoshData#11 from neiljp/image_hoist
Hoist image generation into main()
2 parents 744276a + 6924c90 commit d369447

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

pdf_diff/command_line.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ def mark_difference(hunk_length, offset, boxes, changes):
165165
# there's no reason to hold onto it. It can't be marked as changed twice.
166166
changes.append(boxes.pop(0))
167167

168-
# Turns a JSON object of PDF changes into a PNG and writes it to stream.
169-
def render_changes(changes, styles, stream):
168+
# Turns a JSON object of PDF changes into a PIL image object.
169+
def render_changes(changes, styles):
170170
# Merge sequential boxes to avoid sequential disjoint rectangles.
171171

172172
changes = simplify_changes(changes)
@@ -209,10 +209,7 @@ def render_changes(changes, styles, stream):
209209

210210
img = stack_pages(page_groups)
211211

212-
# Write it out.
213-
214-
img.save(stream, "PNG")
215-
212+
return img
216213

217214
def make_pages_images(changes):
218215
pages = [{}, {}]
@@ -430,7 +427,7 @@ def pdftopng(pdffile, pagenumber, width=900):
430427
def main():
431428
if len(sys.argv) == 2 and sys.argv[1] == "--changes":
432429
# to just do the rendering part
433-
render_changes(json.load(sys.stdin), sys.stdout.buffer)
430+
render_changes(json.load(sys.stdin))
434431
sys.exit(0)
435432

436433
if len(sys.argv) <= 1:
@@ -456,7 +453,9 @@ def main():
456453
right_file = args.pop(0)
457454

458455
changes = compute_changes(left_file, right_file, top_margin=top_margin)
459-
render_changes(changes, styles, sys.stdout.buffer)
456+
img = render_changes(changes, styles)
457+
img.save(sys.stdout.buffer, "PNG")
458+
460459

461460
if __name__ == "__main__":
462461
main()

0 commit comments

Comments
 (0)