I am working on a small project that involves scanning old zines. The zines are unbound and scanned on both sides to a set of image files, which produces scans of the print-oriented layout of the physical pages themselves. It’s not human readable and there is no quick and dirty tool to disassemble the imposed boards into human readable order for creation of a PDF.

I found a bash script that mostly accomplishes the task of splitting an image set into two halves but the script simply numbers the image output sequentially and occasionally also produces garbage output, images of one pixel wide and so forth.

I posted a request to Facebook asking for help and several people kindly replied. Josh Larios, with whom I have had occasional interaction since early blogging days, picked up the starter script and added the missing features.

Josh and Chris Pheifer, a pal from Bloomington, also each found some tools that are intended to do similar things with PDFs.

Here is Josh’s updated script:

#!/bin/bash
# Script to split images in half using ImageMagick
# By Euan McKay
# Modified for reverse imposition (deimposition? exposition?) by RJL20
# Usage:
# ./deimpose.sh outbase 'inglob*'

# You can adjust these settings to suit your needs

FOLDER='pages' # set output folder name
mkdir -p $FOLDER   # create the folder to store split images

OUTPUT='jpg'    # set extension of image type to save

# You shouldn't need to adjust anything below here

OUTBASE=$1
INGLOB=$2

FILES=($INGLOB)
NUMFILES=${#FILES[@]}
FIRST=1
LAST=$((NUMFILES*2))
TOGGLE=1

echo "First: $FIRST; Last: $LAST"

for ITEM in $"${FILES[@]}"        # get items from globbed files
do                          # start loop
    data=`identify "$ITEM" | awk '{print $3}'`                # get image data
    W=`echo $data | sed 's/[^0-9]/ /g' | awk '{print $1}'`  # extract width
    NEWW=$((W/2))                                           # set new width

    if ((TOGGLE)); then
        LEFT=${FOLDER}'/'${OUTBASE}'-'`printf '%03i' $LAST`.${OUTPUT}
        RIGHT=${FOLDER}'/'${OUTBASE}'-'`printf '%03i' $FIRST`.${OUTPUT}
    else
        RIGHT=${FOLDER}'/'${OUTBASE}'-'`printf '%03i' $LAST`.${OUTPUT}
        LEFT=${FOLDER}'/'${OUTBASE}'-'`printf '%03i' $FIRST`.${OUTPUT}
    fi

    convert -verbose -gravity East -chop ${NEWW}x0 "$ITEM" "$LEFT"         # make left half
    convert -verbose -gravity West -chop ${NEWW}x0 "$ITEM" "$RIGHT"        # make right half

    FIRST=$((FIRST+1))
    LAST=$((LAST-1))
    TOGGLE=$((1-TOGGLE))
done                        # end loop

Thanks everyone. Posted here to make it searchable outside of FB.

Leave a Reply

Your email address will not be published.