find /workspace/output -maxdepth 2 -type f -printf '%P %s bytes\n' | sort; python - <<'PY'
import fitz,json,numpy as np
from PIL import Image
from scipy import ndimage as ndi
p='/workspace/output/';d=fitz.open(p+'catalogue_press.pdf');L=json.load(open('/workspace/scratch/layout.json'))
for pg in L:
 page=d[pg['number']-1];rect=page.rect;words=page.get_text('words');small=1e9
 for w in words:
  # Includes three millimetre bleed offset; all live glyphs must be at least eight millimetres from trim.
  space=min(w[0],w[1],rect.width-w[2],rect.height-w[3])*25.4/72-3;small=min(small,space)
 assert small>=8-.05,(pg['number'],small)
 ims=page.get_image_info();print('Page',pg['number'],'min glyph trim inset',round(small,2),'mm')
 for im in ims:
  assert min(im['bbox'])>=0
  x0,y0,x1,y1=im['bbox'];assert x0>=3*72/25.4 and x1<=rect.width-3*72/25.4 and y0>=3*72/25.4 and y1<=rect.height-3*72/25.4
PY