#!/bin/bash # # Syntax: fig2jpg [-h] [-c] [-d density] filename [...] # # Purpose: Transforms .fig files into .jpg files using fig2dev and convert. # By default the fig files are taken from ~/fig/xfig. # However, if the -c flag is given, then the fig files are taken # from the current directory. # The output is always placed into the current directory. # 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: fig2eps, fig2png, eps2jpg # Created: Jul 26, 2007 by Bart De Schutter # Last revised: Jan 2, 2011 by Bart De Schutter # # See http://www.deschutter.info/util/scripts.html for the latest version of # this script. # Status: public # Category: images, xfig # # Process input arguments. # fig_dir=~/fig/xfig density=300 while getopts :hcd: option do case "$option" in h) sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 ;; c) fig_dir=$(pwd) ;; 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 # # Convert fig files into jpg files. # for fname in "$@" do filename="${fname%.fig}" basename="${filename##*/}" if [ -f "$fig_dir/${filename}.fig" ] then fig2dev -L eps -c "$fig_dir/${filename}.fig" | \ convert -antialias -density $density - "${basename}.jpg" else echo >&2 echo >&2 "ERROR: file ${filename}.fig not found." echo >&2 fi done