Auto-generating split pages
Posted by mholmes on 06 Jan 2021 in Activity log
Just a note to self for future reference: One of our source documents came in the form of full-page-spread images, and rather than manually crop them (there are 370), I wrote a bit of JS to generate a bash script which uses ImageMagick to do it. First I renamed all the input files so that they were -0001, -0003, -0005 etc. to allow room for the new ones, then used this:
function writeCropLines(num){ let padNum = num.toString().padStart(4, '0'); let output = 'convert mgchau-' + padNum + '.jpg -crop '; output += '1377x1936+0+0 out/mgchau-' + padNum + '.jpg '; output += '\u000a'; padNum2 = (num + 1).toString().padStart(4, '0'); output += 'convert mgchau-' + padNum + '.jpg -crop '; output += '1497x1936+1096+0 out/mgchau-' + padNum2 + '.jpg '; output += '\u000a'; return output; } function doAll(){ let output = ''; for (var i=1; i<740; i+=2){ output += writeCropLines(i); } return output; } console.log(doAll());
in the browser dev tools to generate the script.