Share your favorite scripts!

This page is intended to be a place to save and share your favorite scripts and code that you use regularly. Each entry should have:
  • a short description of what the script or program does,
  • how to run it,
  • the author's name,
  • where it can be run,
  • the date it was posted,
  • and the date when it was last used.
If you find a script on here that you like and were able to use it, update the "last used on..." date.

Automatically generate an html page from a directory with .eps plots

What it does
Creates a simple html webpage from a directory which contains .eps image files. The html page displays thumbnails of the images, converts the .eps files to .jpg format, and contains links to the image files. To view on the web simply place the entire directory in your webspace area or create a soft link to the directory in your webspace area.
How to run it
./createHTMLpageAllPlots.sh <directory> <optional page title>
Written by
? (posted by Emily Johnson)
Where it can be run
Tested on the Linux Desktop Cluster and on ATLAS lxplus machines
Date posted
10/18/16
Date last used
10/18/16
#! /bin/sh

# you need to run this script from a dir above the 'dirname' destination

if [ $# -lt 1 ] ; then
    echo "
Usage:
$0 <destination> [<comments>]

destination = directory with eps files.
comments    = title for html page.
"
exit 0
fi


destination=$1
dir=$2
nx=4
if [ $# -gt 2 ] ; then  nx=$3 ; fi
tagname=`basename $destination`
DATE=`date`
text=""
TNx=240
JPGx=1100
JPGy=700
JPGres=80


if [ ! -e ${destination} ] ; then
    echo "destination directory (${destination}) does not exist!"
    exit 1
fi


cd ${destination}


  mkdir eps
  mv *.eps eps

  file="index.html"
  blue="#0000FF"
  red="#FF0000"
  black="#000000"
  title="${tagname} - ${dir} (${DATE})"

  mkdir jpg
  mkdir small

  rm -rf ${file}

  echo "<HTML>" >> ${file}
  echo "<TITLE>${title}</TITLE>" >> ${file}
  echo " <BODY>" >> ${file}
  echo "  <CENTER><H1><font color=\"${blue}\">${title}</font></H1></CENTER>" >> ${file}
  echo "<p>" >> ${file}
  echo ${text} >> ${file}
  echo "</p>" >> ${file}

  echo "  <TABLE>" >> ${file}
  echo "   <TR>" >> ${file}

  echo "<a href=\"Events.txt\"><H3><font color=\"${blue}\"> Events and scale </font></H3></a>" >> ${file}

  echo "Creating thumbnails..."

  #########################
  i1=0
  j1=0
  echo "    </TR>" >> ${file}
  echo "  </TABLE>" >> ${file}
  echo "<H1><font color=\"${blue}\">  </font></H1>" >> ${file}
  echo "  <TABLE>" >> ${file}
  echo "   <TR>" >> ${file}

  for epsfile1 in `cd eps; ls *.eps` ; do 

    echo "Converting eps to jpg, ${epsfile1} ..."

      eps1=$epsfile1

      #creating scaled thumbnails !!!
      img1=`echo ${eps1} | sed 's/.eps/.jpg/'`

      #convert -scale ${BGsize} eps/${eps1} jpg/${img1}
      ### Convert eps to jpg without losing resolution! 
      gs -sDEVICE=jpeg -dJPEGQ=${JPGres} -g${JPGx}x${JPGy} -dEPSFitPage -dNOPAUSE -dBATCH -dSAFER -q -sOutputFile=jpg/${img1} eps/${eps1}
      ##gs -sDEVICE=jpeg -dJPEGQ=${JPGres} -g${TNx}x${TNy} -dEPSFitPage -dNOPAUSE -dBATCH -dSAFER -q -sOutputFile=small/TN_${img1} eps/${eps1}
      convert -scale ${TNx} jpg/${img1} small/TN_${img1}

      echo "    <td align=\"center\">" >> ${file}
      echo "      <a href=\"jpg/${img1}\"> <img src=\"small/TN_${img1}\"> </a>" >> ${file}
      eps=`echo $img1 | sed 's/.jpg/.eps/'`
      echo "      <br><a href=\"jpg/${img1}\">${img1}</a>, <a href=\"eps/${eps1}\">[eps]</a>  "  >> ${file}
      echo "    </td>  "  >> ${file}
      i1=`expr $i1 + 1` 
      j1=`expr ${i1} % ${nx}`
      if [ $j1 -eq 0 ] ; then
         echo "   </TR><TR>" >> ${file}
      fi

  done   # loop over all files


  echo "    </TR>" >> ${file}
  echo "  </TABLE>" >> ${file}
  echo "  <br><br>Created ${DATE} by (c) ${USER} using <a href=\"createHTMLpage.sh\">createHTMLpage.sh</a>"  >> ${file}
  echo " </BODY>" >> ${file}
  echo "</HTML>" >> ${file}

  cd ..


-- EmilyJohnson - 18 Oct 2016
Topic revision: r1 - 18 Oct 2016, EmilyJohnson
 

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback