Michael Uplawski |
04-26-2016 02:35 PM |
With Ghostscript, you convert many files to many different image-formats. For a long time, already, I use the following script for this kind of work. I do not recommend the script and just put it here to economize on bad English. Examples are in general easier to understand... ;-)
Check the available Ghostscript devices. I know that for the output of tiffs the script had to be adapted once, but it should normally be okay, like it is.
Code:
#!/bin/bash
#
# prints files to image
# ©2007-2016 Michael Upawski <michael.uplawski@uplawski.eu>
# License-agreement: Modify the file as pleases you; use at your own risk as it
# may do some harm somewhere or not (lay your home in ashes, make you crow's
# feet and what not.., buys you a Volvo, you know that kind of stuff.)
# I forbid use of this script to any European governmental agencies as well as
# to each one of their paying customers.
# defaults
TYPE=tif
DEV=tiff24nc
RES=400x400
PAPER=a4
GS=/usr/bin/gs
SCRIPT=`basename "$0"`
USAGE="Syntax:\n\tuser@machine:$PWD\$ $SCRIPT [file0] <file1> ... <filen>\nWill create 1 file converted to $TYPE for each page in any of the input-files.\
\n\tusr@machine:$PWD/\$ $SCRIPT <output type> [file0] <file1> ... <filen>\nWill instead create files of the specified output type e.g. jpeg, png, pgm"
if [ "$#" -gt 0 ]
then
case "$1" in
tif)
TYPE=tif
DEV=tiffscaled24
shift 1
;;
tiff)
TYPE=tiff
DEV=tiffscaled24
shift 1
;;
jpg)
TYPE=jpg
DEV=jpeg
shift 1
;;
jpeg)
TYPE=jpeg
DEV=jpeg
shift 1
;;
pgm)
TYPE=pgm
DEV=pgm
shift 1
;;
png)
TYPE=png
DEV=png48
shift 1
;;
pcx)
TYPE=pcx
DEV=pcx24b
shift 1
;;
bmp)
TYPE=bmp
DEV=bmp256
shift 1
;;
esac
if [ "$#" -gt 0 ]
then
for inf in "$@"
do
ext=${inf}
DIR=`dirname "$inf"`
if [ "$DIR"=='' ]
then
DIR='.'
fi
OUTPUT="$DIR"/`basename "$inf" ."$ext"`_%04d."$TYPE"
echo "creating files $OUTPUT"
# /usr/bin/gs -SDEVICE="$DEV" -r"$RES" -sPAPERSIZE="$PAPER" -sOutputFile="$OUTPUT" -dNOPAUSE -dBATCH -- "$inf"
"$GS" -SDEVICE="$DEV" -r"$RES" -sPAPERSIZE="$PAPER" -sOutputFile="$OUTPUT" -dNOPAUSE -- "$inf"
done
else
echo -e "ERROR: No files"
echo -e "$USAGE"
fi
else
echo -e "ERROR: No arguments."
echo -e "$USAGE"
fi
Edit: I am a bit dumb, as I forgot that I even have a blog-entry on that subject..: Crete images from PDF and recreate PDF from images
|