#!/bin/bash # # Syntax: eps2jpg [-h] [-d density] eps_file [...] # # Purpose: Uses convert to transform an eps or ps file into a jpg file. # If the file eps_file does not exist, first the extension .eps # is tried, and next the extension .ps. # With the -d flag you can specify the density; the default value is # 300. # The -h flag shows the help info for this command. # # See also: convert, gimp, eps2png # # Note: Does not seem to produce proper output for eps files generated # by matlab (it is suggested to direct create jpg output from within # matlab in that case, or to create output in another format, e.g., png). # Created: May 22, 2006 by Bart De Schutter # Last revised: Sep 3, 2007 by Bart De Schutter # # See http://www.deschutter.info/util/scripts.html for the latest version of # this script. # Status: public # Category: postscript density=300 while getopts :hd: option do case "$option" in h) sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 ;; d) density=${OPTARG} ;; :) echo >&2 echo >&2 "Option -$OPTARG requires an argument." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 echo >&2 exit 1 ;; \?) echo >&2 echo >&2 "Unknown option: $OPTARG" echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 ;; esac done shift $(($OPTIND-1)) if [ $# -eq 0 ]; then echo >&2 echo >&2 "ERROR: ${0##*/} requires at least 1 input argument." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 fi # Enable extended pattern matching operators shopt -q -s extglob for fil in "$@" do convert_fil=1 if [ -f "$fil" ] then basename="${fil%.?(e)ps}" eps_fil="$fil" else basename="$fil" if [ -f "$basename.eps" ] then eps_fil="$basename.eps" else if [ -f "$basename.ps" ] then eps_fil="$basename.ps" else echo >&2 "WARNING: file $fil or $fil.(e)ps not found." convert_fil=0 fi fi fi if [ "$convert_fil" == 1 ] then echo "Converting $eps_fil to jpg file" convert -antialias -density $density "$eps_fil" "$basename.jpg" fi done