[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: print.m problems: png format
From: |
Laurent Mazet |
Subject: |
Re: print.m problems: png format |
Date: |
Thu, 13 Nov 2003 11:42:40 +0100 |
Well,
This morning, with David, we check the script and update it. No more need of the
additional ps file and some new options having been added. You can use pnmflit
instead of pnmrotate (which is slower because it interpolates points when
rotating) and process multiple files. The help message has also been rewritten.
Laurent and David
-8<-
#! /bin/sh -f
VERSION=$(echo '$Revision: 1.9 $' | sed 's/.*\([0-9]\.[0-9.]*\).*/\1/')
RESOL="-r300"
OPTIONS=""
PNMROTATEOPTIONS=""
PNMTRANSPARENT="-background white -transparent =white"
ROTATE="false"
USEPNMFLIP="false"
help=no
addshowpage=""
list=""
trap "exit 1;" 0 1 2 15
while [ $# -gt 0 ]; do
case "$1" in
-ccw) PNMROTATEOPTIONS="90"; PNMFLIPOPTIONS="-ccw" ; ROTATE="true" ;;
-cw) PNMROTATEOPTIONS="-90"; PNMFLIPOPTIONS="-cw" ; ROTATE="true" ;;
-h) help="yes" ;;
-nt) PNMTRANSPARENT="";;
-r*) RESOL="$1" ;;
-r) shift; RESOL="-r$1" ;;
-v) echo "$(basename $0) version $VERSION" >&2; exit 1; ;;
-*) OPTIONS="$OPTIONS $1" ;;
*) list="$list $1" ;;
esac
shift
done
# Set resolution
OPTIONS="$OPTIONS $RESOL"
[ \( -z "$list" \) -o \( "$help" = yes \) ] &&
{ echo "Usage: `basename $0` [-ccw|-cw] [-h] [-rNN] [-v] [-*] <file.eps>...
-ccw: rotate counter clockwise
-cw: rotate clockwise
-h: help message
-nt: no transparency [default transparency]
-rNN: resolution (ex: \"-r75\" for 75 dpi) [default 300 dpi]
-v: show version.
-*: all others options passed to ghostscript
<file1.eps> <file2.eps>... figure's name
generate the PNG file <file>.png from Postscript or EPS file.
" >&2; exit 1; }
for infile in $list; do
# Create output file name
case "${infile}" in
*.ps) base=`basename ${infile} .ps` ;;
*.eps) base=`basename ${infile} .eps` ;;
*) base=`basename ${infile}` ;;
esac
outfile=${base}.png
[ ! -f $infile ] &&
{ echo "Skipping \"$infile\" (file not found)..." >&2; continue; }
head -1 "$infile" | grep -q "^%!" ||
{ echo "Skipping \"$infile\" (not a Postsctipt file)..." >&2; continue; }
echo -n "Processing ${infile} -> ${outfile}:"
[ "$(grep -L -i showpage ${infile})" != "" ] && \
addshowpage="%!\nshowpage\n";
# Now ghostscript it, getting rid of BoundingBox offsets at the same time
if [ "$ROTATE" == "true" ]; then
if [ "$USEPNMFLIP" == "true" ]; then
# Use PNMFLIP
( cat ${infile} ; echo -e ${addshowpage} ) | \
epsffit $(grep '^%%BoundingBox:' ${infile} | head -1 | \
awk '{printf "0 0 %d %d", $4-$2, $5-$3;}') | \
gs -q -dNOPAUSE -dBATCH -sDEVICE=pnm -sOutputFile=- $OPTIONS -f - \
-c quit | pnmcrop | pnmflip $PNMFLIPOPTIONS | \
pnmtopng $PNMTRANSPARENT > ${outfile}
else
# Use PNMROTATE and not PNMFLIP as I get a seg fault with PNMFLIP.
( cat ${infile} ; echo -e ${addshowpage} ) | \
epsffit $(grep '^%%BoundingBox:' ${infile} | head -1 | \
awk '{printf "0 0 %d %d", $4-$2, $5-$3;}') | \
gs -q -dNOPAUSE -dBATCH -sDEVICE=pnm -sOutputFile=- $OPTIONS -f - \
-c quit | pnmcrop | pnmrotate $PNMROTATEOPTIONS | \
pnmtopng $PNMTRANSPARENT > ${outfile}
fi
else
( cat ${infile} ; echo -e ${addshowpage} ) | \
epsffit $(grep '^%%BoundingBox:' ${infile} | head -1 | \
awk '{printf "0 0 %d %d", $4-$2, $5-$3;}') | \
gs -q -dNOPAUSE -dBATCH -sDEVICE=pnm -sOutputFile=- $OPTIONS -f - \
-c quit | pnmcrop | pnmtopng $PNMTRANSPARENT > ${outfile}
fi
echo " done"
done
->8-
--
Dr. Laurent Mazet: Research Engineer /V\ Centre de Recherche de MOTOROLA
Tel: +33 (0)1 69 35 48 30 =-=-=-=-=-=-=-=-=-=-= Email: address@hidden
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------