From esselfe, 2 Years ago, written in Plain Text.
  1. #!/bin/bash
  2.  
  3. [ -z $1 ] && { echo -e "\e[01;33mUsage\e[00m: pics2html DIRNAME OUTFILENAME.html"; exit 22; }
  4.  
  5. if [ -d $1 ]; then
  6.         DIR="$1"
  7. else
  8.         echo -e "\e[01;31mError\e[00m: First argument must be a directory."
  9.         exit 22
  10. fi
  11.  
  12. PICSIZEPROG=/abin/picsize
  13. [ -x $PICSIZEPROG ] && HAVE_PICSIZE=1
  14.  
  15. FILE="$DIR.html"
  16. LIST=$(ls -v $DIR/*{bmp,BMP,jpg,jpeg,JPG,JPEG,png,PNG,gif,GIF} 2>/dev/null)
  17.  
  18. echo -e "<html>\n<head><title>$FILE - Image list</title></head>" > $FILE
  19.  
  20. echo -e '<body bgcolor="#081018">' >> $FILE
  21.  
  22. #declare -i WIDTH
  23. #declare -i HEIGHT
  24. cnt=0
  25. echo "$(echo $LIST |wc -w) files"
  26. for f in $LIST; do
  27.         echo -ne "\r$((++cnt))      "
  28.         # rem filtering only JPG files since other formats are not yet implemented in picsize
  29.         FTYPE=$(file -b --mime-type $f)
  30.         if [ ! -z "$HAVE_PICSIZE" -a "$FTYPE" = "image/jpeg" -a ! "$FTYPE" = "image/png" ]; then
  31.                 SIZE=$($PICSIZEPROG $f 2>/dev/null)
  32.                 WIDTH=$(echo $SIZE |awk '{ print $1 }')
  33.                 HEIGHT=$(echo $SIZE |awk '{ print $2 }')
  34.                 if [ $WIDTH -gt $HEIGHT ]; then
  35.                         echo -e "<img width=\"225px\" height=\"150px\" src=\"$f\"/>" >> $FILE
  36.                 elif [ $WIDTH -lt $HEIGHT ]; then
  37.                         echo -e "<img width=\"150px\" height=\"225px\" src=\"$f\"/>" >> $FILE
  38.                 else
  39.                         echo -e "<img width=\"150px\" height=\"150px\" src=\"$f\"/>" >> $FILE
  40.                 fi
  41.         else
  42.                 echo -e "<img width=\"150px\" height=\"150px\" src=\"$f\"/>" >> $FILE
  43.         fi
  44.         echo -e '<a href="'$f'">'$(basename $f |sed "s/.jpg/J/;s/.png/P/")'</a>' >> $FILE
  45.     done
  46. echo ""
  47.  
  48. echo -e "\n</body>\n</html>" >> $FILE
  49.  
  50. ls -l $FILE
captcha