#!/bin/sh -e for a in "$@" do extension="$(printf "$a" | tail -c 4)" output_dir="$(dirname "$a")/split" output="$output_dir/$(basename "$a" "$extension")" mkdir -p "$output_dir" convert "$a" -crop 50%x100% +repage "$output-%d.jpg" done