#!/bin/bash # # im_histogram [option] 'function' 'basename' # # Plot a graph the histogram function given on the command line, using gnuplot # outpuing a small GIF thumbnail and larger JPG image of the plot. # # The function given must be in the gnuplot functional language, and NOT the # Imagemagick "-fx" format. That is it is 'x' basied with gnuplot operators. # # Options: # -l include a line from 0,0 to 1,1 # -d data read in control points from this data file. # -t title A title string to use on the main JPEG plot image # #### # # WARNING: Input arguments are NOT tested for correctness. # This script represents a security risk if used ONLINE. # I accept no responsiblity for misuse. Use at own risk. # # Anthony Thyssen, October 2004 # PROGNAME=`type $0 | awk '{print $3}'` # search for executable on path PROGDIR=`dirname $PROGNAME` # extract directory of program PROGNAME=`basename $PROGNAME` # base name of program Usage() { # output the script comments as docs echo >&2 "$PROGNAME:" "$@" sed >&2 -n '/^###/q; /^#/!q; s/^#//; s/^ //; 3s/^/Usage: /; 2,$ p' \ "$PROGDIR/$PROGNAME" exit 10; } while [ $# -gt 0 ]; do case "$1" in --help|--doc*) Usage ;; # Documentation -l) line=true ;; -d) shift; data=$1 ;; -t) shift; title=$1 ;; --) shift; break ;; # end of user options -*) Usage "Unknown option \"$1\"" ;; *) break ;; # end of user options esac shift # next option done [ $# -eq 0 ] && Usage "Missing function to plot" [ $# -eq 1 ] && Usage "Missing output filename" [ $# -gt 2 ] && Usage "Too many arguments" func=$1 name=$2 # --------------------------------------------- # Main plot image (JPG) ( echo 'set terminal png' echo 'set key left' echo 'set xtics .5' echo 'set ytics .5' echo 'set mxtics .25' echo 'set mytics .25' [ "$title" ] && echo "set title \"$title\"" if [ "$line" ]; then if [ "$data" ]; then echo "plot [0:1][0:1] '$data', $func, x" else echo "plot [0:1][0:1] $func, x" fi elif [ "$data" ]; then echo "plot [0:1][0:1] '$data', $func" else echo "plot [0:1][0:1] $func" fi ) | gnuplot | convert - $name.jpg chmod 644 $name.jpg # ------ # Icon plot image (GIF) ( echo 'set terminal png' echo 'unset key' echo 'set xtics .5' echo 'set ytics .5' echo "set size .3,.3" if [ "$line" ]; then if [ "$data" ]; then echo "plot [0:1][0:1] '$data', $func, x" else echo "plot [0:1][0:1] $func, x" fi elif [ "$data" ]; then echo "plot [0:1][0:1] '$data', $func" else echo "plot [0:1][0:1] $func" fi ) | gnuplot | \ convert - -trim +repage -bordercolor white -border 5 \ -resize '150x100!' -colors 256 $name.gif . ../generate_options gif=$name.gif if [ "$gifsicle" ]; then echo "Optimizing GIF format of \"$gif\"..." gifsicle -O -b $gif fi chmod 644 $gif