assuming you have scanned two pages at one time and you want split in single pages
and your first image has name 0-000.jpg
you can split in single pages all your scans, by calculating the cropping dimensions and coordinates, by reading width and height from first image and dividing by two its width, to have the dimensions and the cropping coordinates for even and odd pages
this is my first attempt to create a splitting script, so, many thing may be enhanced
for graphicsmagick
- Code: Select all
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"`"
quality="$(gm identify -verbose $(ls *.jpg | head -n1) | grep Quality | cut -d: -f2)"
for FILE in *.jpg ; do gm convert -quality $quality -crop "$halfwidth"x"$height"+0+0 "$FILE" "${FILE%%.jpg}-A.jpg" ; mv `ls *.jpg | grep A` even-odd ; gm convert -quality $quality -crop "$width"x"$height"+"$halfwidth"+0 "$FILE" "${FILE%%.jpg}-B.jpg" && mv `ls *.jpg | grep B` even-odd
done ;
for imagemagick
- Code: Select all
if [ ! -e even-odd ]; then mkdir even-odd; fi
first="`ls -1 *.jpg | head -n1`"
let "halfwidth=` identify -format '%w \n' "$first"`/2"
width="`identify -format '%w \n' "$first"`"
height="`identify -format '%h \n' "$first"`"
quality="$(identify -verbose $(ls *.jpg | head -n1) | grep Quality | cut -d: -f2)"
for FILE in *.jpg ; do convert -quality $quality -crop "$halfwidth"x"$height"+0+0 "$FILE" "${FILE%%.jpg}-A.jpg" ; mv `ls *.jpg | grep A` even-odd ; convert -quality $quality -crop "$width"x"$height"+"$halfwidth"+0 "$FILE" "${FILE%%.jpg}-B.jpg" && mv `ls *.jpg | grep B` even-odd
done ;
2nd step, joining all images in a single pdf
I use sam2p and pdftk
- Code: Select all
#!/bin/bash
directory=`pwd`
for file in $directory/*.jpg
do
filename=${file%.jpg}
sam2p $filename.jpg $filename.pdf
done
- Code: Select all
pdftk *.pdf cat output out.pdf && pdftk out.pdf output fixed.pdf && mv fixed.pdf out.pdf
