#!/usr/bin/env bash # -------------------------------------------- # Thumbnailer for Graphviz .DOT files # # Procedure : # http://bernaerts.dyndns.org/linux/76-gnome/333-gnome-shell-graphviz-viewer-thumbnailer # Depends on : # * dot (graphviz package) # * pngtopnm, pnmtopng and pnmscalefixed (netpbm package) # Parameters : # $1 - path of graphviz file # $2 - path of generated thumbnail # $3 - height of thumbnail in pixels # Revision history : # 04/08/2013, V1.0 - Creation by N. Bernaerts # 25/04/2015, V1.1 - Convert to bash # 07/10/2017, V1.2 - Conversion to URI and speedup with netpbm # 15/12/2018, V1.3 - Rework for bubblewrap compatibility # ------------------------------------------- # check tools availability command -v dot >/dev/null 2>&1 || { echo "[error] dot missing"; exit 1; } command -v pngtopnm >/dev/null 2>&1 || { echo "[error] pngtopnm missing"; exit 1; } command -v pnmtopng >/dev/null 2>&1 || { echo "[error] pnmtopng missing"; exit 1; } command -v pnmscalefixed >/dev/null 2>&1 || { echo "[error] pnmscalefixed missing"; exit 1; } # check params [ "$3" = "" ] && { echo "[error] 3 params are needed : file file-thumb thumb-size"; exit 1; } # get parameters FILE_LOCAL="$1" FILE_THUMB="$2" SIZE="$3" # generation dot -Tpng "${FILE_LOCAL}" | pngtopnm - | pnmscalefixed -xysize ${SIZE} ${SIZE} - | pnmtopng -downscale -compression 0 - > "${FILE_THUMB}"