Skip to content

Instantly share code, notes, and snippets.

@drmalex07
Created May 8, 2017 18:05
Show Gist options
  • Save drmalex07/1088544cfc121acab0463691f71fef0a to your computer and use it in GitHub Desktop.
Save drmalex07/1088544cfc121acab0463691f71fef0a to your computer and use it in GitHub Desktop.
Merge (montage) multiple DOT files in a single PNG. #bash #graphviz #montage #dot
#!/bin/bash
#
# Create a single PNG image from a sequence of DOT files (describing a graph)
#
# Parse command line
outfile="graph.png"
while getopts ":ho:" opt; do
case $opt in
o)
outfile="${OPTARG}"
;;
h)
echo "Usage: ${0} -o <outfile> <input1.dot> <input2.dot> ..."
;;
?)
echo "Invalid option: ${OPTARG}"
;;
esac
done
shift $((OPTIND-1))
# Create temporary images for each DOT
n=${#}
images=( )
let i=0
for dotfile in ${@}; do
name=$(basename "$dotfile")
f=$(tempfile --prefix "${name%%.dot}")
dot -Tpng ${dotfile} > ${f}
images[$i]=${f}
let i=i+1
done
# Montage
echo "${outfile}"
montage ${images[*]} -tile "${n}x1" -geometry +5+0 ${outfile}
# Cleanup temporary files
for f in ${images[@]}; do rm ${f}; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment