#! /usr/bin/python3 # Last edited on 2026-01-12 06:14:41 by stolfi # Clips out from the BL 2014 Pharma pages all jar images, chopped and filled to # the same size, with jar bottom ~100 pixels above the image bottom. # Images go into "jar-images/{pnum}.{jnum}.png" where {pnum} is the page's p-number # and {jnum} is th jar number in the page {1,2,3,..}. from process_funcs import bash from sys import stderr as err, stdout as out def main(): FB = "work/FromBeinecke" jdir = "jar-images" bash(f"mkdir -p {jdir}") width_all = 460 # Normalized width of clip. height_all = 1400 # Normalized height of clip from baseline. depth_all = 200 # Normalized depth of clip below baseline dtop = 100 # Min crop distance from top of page image. tsize_all = 100 # Extra space at bottom for label def jout(pjnum, fnum, xaxis, ybase, height, depth): # {pjnum} Page p-number, dot, jar number. # {fnum} Page f-number. # {xaxis} Pixel col of axis of jar. # {ybase} Pixel row of baseline (bottom center) of jar. # {height} Height of jar above baseline. # {depth} Depth of jar below baseline. # Compute crop parameters {szx,szy,ex,ey} ex = xaxis - width_all/2; assert ex >= 0, f"bad xaxis, {ex = }" ey = max(dtop, ybase - height) szx = width_all szy = ybase - ey + depth ofile = f"{jdir}/{pjnum}.jpg" crop_args = f"-crop '{szx}x{szy}+{ex}+{ey}'" bg_args = "-background 'rgb(60%,50%,40%)'" resh_vsz = szy - depth + depth_all resh1_args = f"+repage -gravity north -extent '{width_all}x{resh_vsz}'" resh2_args = f"+repage -gravity south -extent '{width_all}x{height_all+depth_all}'" reshape_args = f"{bg_args} {resh1_args} {resh2_args}" base_args = f"-stroke red -draw 'line 0,{height_all} {width_all},{height_all}'" lab0_args = f"-fill 'rgb(0%,0%,100%)' -font 'Courier-Bold' -pointsize 40 -gravity South" lab1_args = f"-annotate '+0+50' '{fnum}'" lab2_args = f"-annotate '+0+5' '{pjnum}'" label_args = f"{lab0_args} {lab1_args} {lab2_args}" # bash(f"convert {FB}/{fnum}.jpg {crop_args} {reshape_args} {base_args} {label_args} {ofile}") bash(f"convert {FB}/{fnum}.jpg {crop_args} {reshape_args} {label_args} {ofile}") # bash(f"display -title '%f' -resize '50%' {ofile}") return # .................................................................... jout( "p179.1", "f88r", 400, 1235, 990, 70 ) # + jout( "p179.2", "f88r", 420, 2276, 1000, 70 ) # + jout( "p179.3", "f88r", 420, 3326, 990, 80 ) # + jout( "p180.1", "f88v", 666, 1132, 1000, 60 ) # + jout( "p180.2", "f88v", 694, 1768, 620, 70 ) # + jout( "p180.3", "f88v", 686, 3124, 1110, 90 ) # + jout( "p181.1", "f89r1", 2994, 920, 720, 70 ) # + jout( "p181.2", "f89r1", 3062, 1844, 740, 60 ) # + jout( "p181.3", "f89r1", 3054, 3240, 1330, 60 ) # + jout( "p182.1", "f89r2", 5436, 1086, 830, 70 ) # + jout( "p182.2", "f89r2", 5432, 1770, 660, 70 ) # + jout( "p182.3", "f89r2", 5444, 2534, 760, 70 ) # + jout( "p182.4", "f89r2", 5452, 3360, 730, 80 ) # + jout( "p183.1", "f89v3", 471, 1145, 860, 60 ) # + jout( "p183.2", "f89v3", 495, 2254, 1020, 80 ) # + jout( "p183.3", "f89v3", 552, 3038, 760, 70 ) # + jout( "p184.1", "f89v1", 875, 1151, 820, 50 ) # + jout( "p184.2", "f89v1", 890, 2732, 1380, 90 ) # + jout( "p199.1", "f99r", 420, 799, 560, 70 ) # + jout( "p199.2", "f99r", 411, 1540, 480, 70 ) # + jout( "p199.3", "f99r", 405, 2170, 530, 60 ) # + jout( "p199.4", "f99r", 390, 2910, 530, 80 ) # + jout( "p200.1", "f99v", 504, 874, 660, 80 ) # + jout( "p200.2", "f99v", 531, 1486, 550, 70 ) # + jout( "p200.3", "f99v", 564, 2104, 590, 100 ) # + jout( "p200.4", "f99v", 564, 2800, 490, 80 ) # + jout( "p201.1", "f100r", 282, 649, 520, 50 ) # + jout( "p201.2", "f100r", 432, 2173, 520, 70 ) # + jout( "p202.1", "f100v", 896, 758, 680, 70 ) # + jout( "p203.1", "f101r1", 3098, 676, 510, 80 ) # + jout( "p203.2", "f101r1", 3056, 2288, 660, 80 ) # + jout( "p205.1", "f101v2", 384, 697, 550, 70 ) # + jout( "p205.2", "f101v2", 438, 1324, 580, 70 ) # + jout( "p205.3", "f101v2", 468, 2044, 650, 60 ) # + jout( "p207.1", "f102r1", 2970, 790, 570, 70 ) # + jout( "p207.2", "f102r1", 2992, 1630, 590, 60 ) # + jout( "p207.3", "f102r1", 3032, 2450, 640, 80 ) # + jout( "p208.1", "f102r2", 5384, 890, 590, 80 ) # + jout( "p208.2", "f102r2", 5380, 1742, 600, 70 ) # + jout( "p208.3", "f102r2", 5384, 2642, 770, 80 ) # + jout( "p209.1", "f102v2", 423, 1419, 990, 70 ) # + jout( "p209.2", "f102v2", 510, 2403, 940, 80 ) # + jout( "p210.1", "f102v1", 528, 1384, 1120, 60 ) # + jout( "p210.2", "f102v1", 600, 2500, 810, 90 ) # + return # ---------------------------------------------------------------------- main()