Skip to content

Commit d452507

Browse files
committed
zealous cropping problem
It was zealous cropping at each page-group but keeping the dimensions variables for the next page-group, resulting in wider anw wider margins. Compute the dimensions once for all pages, and then go back and crop them.
1 parent e808493 commit d452507

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pdf-diff.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,11 @@ def zealous_crop(page_groups):
303303
minx = min(bbox[0], minx) if minx is not None else bbox[0]
304304
maxx = max(bbox[2], maxx) if maxx is not None else bbox[2]
305305
width = max(width, pdf.size[0]) if width is not None else pdf.size[0]
306-
if width != None:
307-
minx = max(0, minx-int(.02*width)) # add back some margins
308-
maxx = min(width, maxx+int(.02*width))
306+
if width != None:
307+
minx = max(0, minx-int(.02*width)) # add back some margins
308+
maxx = min(width, maxx+int(.02*width))
309309
# do crop
310+
for grp in page_groups:
310311
for pg in grp[idx]:
311312
im = grp[idx][pg]
312313
bbox = ImageOps.invert(im.convert("L")).getbbox() # .invert() requires a grayscale image

0 commit comments

Comments
 (0)