Skip to content

Instantly share code, notes, and snippets.

@seancheung
Last active June 2, 2017 19:13
Show Gist options
  • Save seancheung/19823f4c90c51eeec5185783e0a50c23 to your computer and use it in GitHub Desktop.
Save seancheung/19823f4c90c51eeec5185783e0a50c23 to your computer and use it in GitHub Desktop.
Slice images for making comic
#!/bin/bash
slice() {
DIR=$(gm identify -format %d "$1")
FILENAME=$(gm identify -format %t "$1")
EXTENSION=$(gm identify -format %e "$1")
WIDTH=$(gm identify -format %w "$1")
OFFSET=$((WIDTH/2))
if [ "$DIR" ]; then
FILENAME="${DIR}/${FILENAME}"
fi
gm convert -crop 50x100+0+0% "$1" "${FILENAME}_2.${EXTENSION}"
gm convert -crop 50x100+${OFFSET}+0% "$1" "${FILENAME}_1.${EXTENSION}"
}
slice_all() {
for file in "$1"/*$2; do
slice "$file"
unlink "$file"
done
}
if [[ -d "$1" ]]; then
slice_all "$1" $2
elif [[ -f "$1" ]]; then
slice "$1"
unlink "$1"
else
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment