Added ionice when available.
[scripts.git] / picstohtml.sh
1 #!/bin/bash
2
3 #########################################################################
4 # This program is free software: you can redistribute it and/or modify  #
5 # it under the terms of the version 3 of the GNU General Public License #
6 # as published by the Free Software Foundation.                         #
7 #                                                                       #
8 # This program is distributed in the hope that it will be useful, but   #
9 # WITHOUT ANY WARRANTY; without even the implied warranty of            #
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      #
11 # General Public License for more details.                              #
12 #                                                                       #
13 # You should have received a copy of the GNU General Public License     #
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.  #
15 #                                                                       #
16 # Written by and Copyright (C) Francois Fleuret                         #
17 # Contact <francois@fleuret.org> for comments & bug reports             #
18 #########################################################################
19
20 function error () {
21     echo $1 1>&2
22     exit 1
23 }
24
25 ######################################################################
26 # Create the directories
27
28 if [[ -z $1 ]] || [[ -z $2 ]]; then
29     echo "$0 <image directory> <result directory>"
30     exit 1
31 fi
32
33 if [[ ! -d $1 ]]; then
34     echo "Can not find directory $1"
35     exit 1
36 fi
37
38 mkdir $2 || error "Can not create $2."
39 mkdir $2/pics || error "Can not create $2/pics"
40 mkdir $2/thumbs || error "Can not create $2/thumbs"
41
42 ######################################################################
43 # Generate the html header
44
45 cat > $2/index.html <<EOF
46 <?xml version="1.0" encoding="iso-8859-1"?>
47 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
48
49 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
50
51 <head>
52 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
53 <title></title>
54 </head>
55
56 <body>
57
58 EOF
59
60 ######################################################################
61 # Generate the thumbnails, html content and copy the images
62
63 for i in $(find $1 -type f | sort); do
64     FILENAME=$(basename $i)
65     convert 2> /dev/null -geometry 180x120 $i $2/thumbs/${FILENAME}.jpg
66
67     if [[ $? == 0 ]]; then
68         echo "Copying ${FILENAME}"
69         cp $i $2/pics/${FILENAME}
70         echo "<a href=\"./pics/${FILENAME}\"><img src=\"./thumbs/${FILENAME}.jpg\" /></a>" >> $2/index.html
71     else
72         echo "Ignoring $i (not an image?)"
73     fi
74
75 done
76
77 ######################################################################
78 # Generate the footer of the html file
79
80 cat >> $2/index.html <<EOF
81 </body>
82
83 </html>
84 EOF
85
86 ######################################################################