#!/bin/bash # # im_profile [option] input_image output_profile_image # # Plot a graph the horizontal grayscale image given, and include a # copy of the input image as the X axxis of the graph. # # Options # -s generate a 100 pixel wide image instead of 300 pixels # #### # # 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, 5 July 2008 # 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 -s) SMALLER=true ;; -) break ;; # STDIN, end of user options --) shift; break ;; # end of user options -*) Usage "Unknown option \"$1\"" ;; *) break ;; # end of user options esac shift # next option done [ $# -eq 0 ] && Usage "Missing input_image" [ $# -gt 2 ] && Usage "Too many arguments" # Temporary working images (with auto-clean-up on exit) input="/tmp/im_profile_$$.miff" trap "rm -f $input; exit 0" 0 trap "rm -f $input; exit 1" 1 2 3 15 convert "$1" +repage -gravity center -crop 0x1+0+0 +repage $input [ "$?" -eq 0 ] || Usage "Invalid Input Image" output="$2" # same output image filename (or special format) [ $# -ne 2 ] && output="show:" # --------------------------------------------- [ -f ./generate_options ] && source ./generate_options [ -f ../generate_options ] && source ../generate_options [ -f ../../generate_options ] && source ../../generate_options [ "$page_bg_color" ] || page_bg_color=LightSteelBlue size=300 rsize=298x15 gsize=340 gheight=160 # creates a 300x150 image if [ "$SMALLER" ]; then size=150 rsize=148x10 gsize=190 gheight=100 # created a 150x85 image fi # Gnuplot of a Level function #im_func='-sigmoidal-contrast 8x50%' #name=x: { echo "set terminal png size $gsize,$gheight" echo 'unset key' echo 'set format ""' #echo 'set ytics ( 0.25, 0.5, 0.75 ) scale 4' #echo 'set xtics ( 30, 60, 90 ) scale 4' #echo -n 'plot [0:119][0:1] "-" binary format="%ushort" endian=swap' #echo ' array=120 using ($1/65535) with lines' #convert -size 1x120 gradient: -rotate 90 $im_func -depth 16 gray:- #echo 'set xtics ( 300, 600, 900 ) scale 4' echo 'plot [0:'${size}'][0:1] "-" using 0:($3/65535) with lines' convert "$input" -depth 16 -resize ${size}x1\! txt:- |\ tail -n+2 | tr -sc '0-9\n' ' ' } | gnuplot | \ convert -background $page_bg_color -bordercolor $page_bg_color \ "$input" -resize ${rsize}\! \ -bordercolor black -border 1x1 -chop 0x1+0+0 \ \( - -trim +repage \) +swap -append \ "$output" [ -f "$output" ] && chmod 644 "$output"