pdf2png 409 B

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