Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
#!/bin/bash
# Output the postscript file as black and white PNG.
# For some reason, ghostscript can't just read the bounding box and output
# an image that size. So we have to go the long way, determine the bounding
# box, then re-create that with the size and offset determined.
##
if [ $# -ne 2 ] ; then
echo "usage: $0 <rsolution-dpi> <filename>"
exit 1
fi
DPI=$1
IN_PS=$2
GS="gs -q -dNOPAUSE -dBATCH"
# Extract offset and size. Offset we need to manually shift the content to the
# origin (as gs does not seem to have an option for it). The size we need
# to know exactly how many pixels need to be rendered.
# Extracting both from the bounding-box run, returned as a "<RES>:<translate>"
# tuple.
#
# Adding some border (1 point offset hence 2 point size), as the
# pixel-size is rounded numbers, gs fails to generate negative offsets in
# the bbox output and we want some space around.
EXTRACT=$($GS -sDEVICE=bbox -sOutputFile=- $IN_PS 2>&1 | \
awk "/%HiResBoundingBox/ {
printf(\"%dx%d:%.1f %.1f translate\",
$DPI * (\$4 - \$2 + 2) / 72, $DPI * (\$5 - \$3 + 2) / 72,
-(\$2 - 1), -(\$3 - 1)); }")
RES=$(echo "$EXTRACT" | awk -F: '{print $1}')
TRANSLATE=$(echo "$EXTRACT" | awk -F: '{print $2}')
#echo "Resolution $RES ; $TRANSLATE" > /dev/stderr
# Now the actual output.
(echo "$TRANSLATE" ; cat "$IN_PS" ) | $GS -sDEVICE=pngmono -sOutputFile=- -r${DPI}x${DPI} -g$RES -
9c0a35f75This file is pinned to the selected release. Download the original to open it in your design tool.