logo

scripts

A bunch of scripts, some to be moved to their own repository git clone https://anongit.hacktivis.me/git/scripts.git/

genethumb.sh (4127B)


  1. #!/bin/sh
  2. # genethumb.sh - Génération de thumbnails mortels de ta mère
  3. # (c) 3 Jan 1998: version 0.0.4 by Samuel Hocevar <sam@via.ecp.fr>
  4. # 22 May 2000: version 0.0.5 by Samuel Hocevar <sam@via.ecp.fr>
  5. # 15 Nov 2000: version 0.0.6 by Samuel Hocevar <sam@zoy.org>
  6. # with code from Sven Hartge <hartge@ds9.argh.org>
  7. # 13 Dec 2000: version 0.0.7 by Samuel Hocevar <sam@zoy.org>
  8. # now compatible with old ImageMagick versions
  9. # added --rows option
  10. # 27 Apr 2003: version 0.0.8 by Sam Hocevar <sam@zoy.org>
  11. # removed all bashisms
  12. # now compatible with all ImageMagick versions
  13. # 2014-02-28: version 0.0.9 by Haelwenn Monnier (lanodan) <haelwenn.monnier@free.fr>
  14. #
  15. # This program is free software; you can redistribute it and/or modify
  16. # it under the terms of the GNU General Public License as published by
  17. # the Free Software Foundation; either version 2 of the License, or
  18. # (at your option) any later version.
  19. #
  20. # This program is distributed in the hope that it will be useful,
  21. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. # GNU General Public License for more details.
  24. #
  25. # You should have received a copy of the GNU General Public License
  26. # along with this program; if not, write to the Free Software
  27. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  28. version=0.0.9
  29. THFILE=index.html
  30. THDIR=.thumbnails
  31. THEXT=png # change this to jpeg or whatever you want
  32. THWIDTH=120 # thumbnail width
  33. THHEIGHT=90 # thumbnail height
  34. if [ "$1" != "" ] then
  35. THWIDTH=$1
  36. fi
  37. if [ "$2" != "" ] then
  38. THHEIGHT=$2
  39. fi
  40. echo "genethumb.sh v$version -- report bugs to Haelwenn Monnier (lanodan) <haelwenn.monnier@free.fr>"
  41. echo "usage: genethumb.sh [thumbnails width] [thumbnails height]"
  42. if [ -w $THFILE ]
  43. then
  44. echo "moving $THFILE to $THFILE~"
  45. mv -f $THFILE $THFILE~
  46. fi
  47. if [ ! -d $THDIR ]
  48. then
  49. echo "creating thumbnail directory $THDIR"
  50. mkdir $THDIR
  51. fi
  52. cat > $THFILE << EOF
  53. <!DOCTYPE html>
  54. <html>
  55. <head>
  56. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" charset="utf-8"/> <!-- ugly hack to have legacy and html5 encoding -->
  57. <meta name="GENERATOR" content="genethumb.sh version $version" />
  58. <meta name="Description" content="thumbnails of $PWD" />
  59. <title>Index of $PWD</title>
  60. <style type="text/css">
  61. a { display:block; }
  62. td.center { text-align: center; }
  63. td.nowrap { white-space: nowrap; }
  64. blockquote.center { text-align: center; }
  65. </style>
  66. </head>
  67. <body>
  68. <h2>Index of $PWD</h2>
  69. <span align="right">generated by <a href="http://sam.zoy.org/projects/unix/genethumb.html">genethumb.sh</a> version $version </span>
  70. <hr />
  71. EOF
  72. #find . -type f -maxdepth 1 | sed 's,^\./,,' | while read file // Uwwh What a ugly command
  73. for file in *.(jpg|jpeg|png|gif); do newfile="$THDIR/$file.$THEXT";
  74. failed=0
  75. echo -n "* $file: "
  76. if [ -r "$newfile" ] then
  77. echo 'thumbnail already exists.'
  78. else
  79. convert -auto-orient -thumbnail ${THWIDTH}x${THHEIGHT} "$file" "$newfile" >/dev/null 2>&1
  80. if [ ! -r "$newfile" ] then
  81. echo "failed creating."
  82. failed=1
  83. else
  84. echo "done."
  85. fi
  86. fi
  87. if [ "$failed" = "0" ] then
  88. if [ -e "$newfile.info" ] then
  89. read filesize coordinates oldcoords compat < "$newfile.info"
  90. fi
  91. if expr "$version" ">" "$compat" >/dev/null 2>&1 then
  92. read oldcoords filesize << EOF
  93. `identify -format '%wx%h %b' "$file" | head -1`
  94. EOF
  95. coordinates=`identify -format '%wx%h' "$newfile" | head -1`
  96. rm -f "$newfile.info"
  97. echo $filesize $coordinates $oldcoords $version > "$newfile.info"
  98. echo " $newfile.info written."
  99. fi
  100. j="`echo $file | cut -b1-20`"
  101. if [ "$file" != "$j" ] then
  102. j="`echo $file | cut -b1-17`..."
  103. fi
  104. cat >> $THFILE << EOF
  105. <a href="$file"
  106. width="`echo $coordinates | cut -f1 -dx`"
  107. height="`echo $coordinates | cut -f2 -dx`">
  108. <img alt="$file ($oldcoords)" src="$newfile" /><br />
  109. $j<br />
  110. $oldcoords ($filesize)
  111. </a>
  112. EOF
  113. done
  114. echo "done."
  115. echo ' </body>
  116. </html>' >> $THFILE