#!/bin/bash -eu # uses graphics magick to extract images from a pdf as png if ! which gm &>/dev/null; then echo "requires gm convert..." && exit 1 elif [ -z "${1:-}" ] || [ ! -f "$1" ]; then echo "No file supplied..." && exit 1 fi base=$(basename "$1") out=${base%.*} if [ -n "${2:-}" ] && [[ ! -f "$2" || -d "$2" ]]; then out="$2" fi mkdir -p "$out" gm convert -density 300 "$1" +adjoin ${out}/%d.png