@@ -165,8 +165,8 @@ def mark_difference(hunk_length, offset, boxes, changes):
165
165
# there's no reason to hold onto it. It can't be marked as changed twice.
166
166
changes .append (boxes .pop (0 ))
167
167
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 ):
170
170
# Merge sequential boxes to avoid sequential disjoint rectangles.
171
171
172
172
changes = simplify_changes (changes )
@@ -209,10 +209,7 @@ def render_changes(changes, styles, stream):
209
209
210
210
img = stack_pages (page_groups )
211
211
212
- # Write it out.
213
-
214
- img .save (stream , "PNG" )
215
-
212
+ return img
216
213
217
214
def make_pages_images (changes ):
218
215
pages = [{}, {}]
@@ -430,7 +427,7 @@ def pdftopng(pdffile, pagenumber, width=900):
430
427
def main ():
431
428
if len (sys .argv ) == 2 and sys .argv [1 ] == "--changes" :
432
429
# to just do the rendering part
433
- render_changes (json .load (sys .stdin ), sys . stdout . buffer )
430
+ render_changes (json .load (sys .stdin ))
434
431
sys .exit (0 )
435
432
436
433
if len (sys .argv ) <= 1 :
@@ -456,7 +453,9 @@ def main():
456
453
right_file = args .pop (0 )
457
454
458
455
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
+
460
459
461
460
if __name__ == "__main__" :
462
461
main ()
0 commit comments