Save graphics to image files via a script

From Cassandra

Jump to: navigation, search

This script will call up all of your graphics (recursively from the top-level given directory specified on the command line) in sequence and then capture a screenshot to a file in the format specified. The image is saved in a new directory (specified in the script) that mimics the actual directory structure of the graphics directory.

  1. You must install the imagemagick suite for this script to work as it uses the import utility which is provided therein. imagemagick can be found at [1] for whatver version of solaris you are running
  2. You will want to change the HOME variable to wherever you plan to install the script, and then also if you don't want PNG type images, you can change that in the second to last line (change the file extension to something other than '.png' such as '.jpg')
  3. The script takes only one command line argument which is the top-level directory where the graphics reside
  4. The source of the script is below:
#!/bin/sh
HOME=/opt/jeremy/call_graphics
LOGS=$HOME/logs
IMG_DIR=$HOME/graphics
dm=`hostname`
display=0:0
if [ $# -ne 1 ]
then
    echo
    echo "Usage: $0 dir"
    echo
    exit
else
    dir=$1
fi
mkdir -p $IMG_DIR
mkdir -p $LOGS
exec >$LOGS/`basename $0`.$$ 2>&1
# disable bell
xset -display $display -b b off
list=`find $dir \( -name "*.fdf" -o -name "*.FDF" \)`
for x in $list
do
    name=`basename $x | sed s/\.fdf//`
    orig_dir=`dirname $x`
    echo $name
    /usr/local/pref -$dm DMCMD $x
    sleep 5
    mkdir -p $IMG_DIR/$orig_dir
    import -display $display -window root $IMG_DIR/$orig_dir/$name.png
done
Personal tools