We are so lucky!

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

We are so lucky!

Sean P. DeNigris
Administrator
Problem: Scanning a bi-fold pamphlet produced a PDF with two non-contiguous pages per scanned image. After converting each page of the PDF into a png, compare the following approaches to split them in half:

Assembler... I mean Write-Only... I mean Shell Solution [1]:
#!/bin/sh
if [ ! -e even-odd ]; then mkdir even-odd; fi
first="`ls -1 *.jpg | head -n1`"
let "halfwidth=`gm identify -format '%w \n' $first`/2"
width="`gm identify -format '%w \n' $first`"
height="`gm identify -format '%h \n' $first`"
for FILE in *.jpg ; do convert -crop "$halfwidth"x"$height"+0+0 "$FILE" "$FILE-A.jpg" ; mv `ls *.jpg | grep A` even-odd ; convert -crop "$width"x"$height"+"$halfwidth"+0 "$FILE" "$FILE-B.jpg" && mv `ls *.jpg | grep B` even-odd
 done ;

Smalltalk solution:
PsProcessPageImages>>#splitPages
        imageFiles do: [ :file |
                self currentFile: file.
                self splitCurrentImage.
                index := self index + 1 ].

PsProcessPageImages>>#splitCurrentImage
        self index odd
                ifTrue: [ self rightFirstSplitCurrentImage ]
                ifFalse: [ self leftFirstSplitCurrentImage ]
etc...

One fun change was:
  width="`gm identify -format '%w \n' $first`"
which became:
  imageForm width "oh yeah, we can treat the image as a real object and just ask it what its width is!"

[1] http://ubuntuforums.org/showthread.php?t=1665621
Cheers,
Sean