#! /bin/bash # # Use Ghostscript to add density information for the bitmapped file (this # is needed to make bitmapped images work "correctly" in PDF files - it is a # topic in its own right so I'll skip over this for the moment - 100 is a good # value!...) BC="/usr/bin/bc -l" TMPDIR="/tmp" DENSITY_MONITOR=100 FACTOR=4 DENSITY_NEW=$(echo "scale = 0 ; $FACTOR * $DENSITY_MONITOR" | $BC) GEOMETRY_NEW=$(echo "scale = 0 ; 100.0 / $FACTOR" | $BC) SCALE=$(echo "scale = 2 ; 1.0 / $FACTOR" | $BC) echo "############################################################" echo "" echo "Processing file $1.png" echo "" echo "DENSITY_MONITOR=$DENSITY_MONITOR" echo "FACTOR=$FACTOR" echo "DENSITY_NEW=$DENSITY_NEW" echo "GEOMETRY_NEW=$GEOMETRY_NEW" echo "SCALE=$SCALE" # convert -density $DENSITY $1.png $1.eps # eps2png -res $DENSITY $1.eps # Save the file with a random name somewhere - we'll need it... # We use the RANDOM environment variable for the random part. TMPNAME=$1_$RANDOM cp $1.png $TMPDIR/$TMPNAME.png # convert -density $DENSITY_NEW -geometry ${GEOMETRY_NEW}% $1.png $1.eps convert -density $DENSITY_NEW $1.png $1.eps # eps2png -resolution $DENSITY_NEW -scale $SCALE $1.eps eps2png -resolution $DENSITY_NEW $1.eps # Use ImageMagick to convert to EPDF convert -density $DENSITY_MONITOR $1.png $1.epdf # Rename the file so that it ends in pdf - pdftex wants this! mv $1.epdf $1.pdf # This completes the creation of an eps and a pdf image # with the right density. # Unfortunately, the eps image thus created, will show # in 1/$FACTOR the right size in the PS file. # So we use the temporarily saved file for a second try, # this time with the monitor density. convert -density $DENSITY_MONITOR $TMPDIR/$TMPNAME.png $1.eps rm $TMPDIR/$TMPNAME.png