3 # makegallery.sh - builds a simple 'gallery' from a collection of images
4 # Copyright (C) 2004 Brett Parker <iDunno@sommitrealweird.co.uk>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 if [[ -z $TITLE ]]; then
28 if [[ -z $CONVERTTOOL ]]; then
29 CONVERTTOOL="/usr/bin/convert"
32 if [[ -z $FINDCOMMAND ]]; then
33 FINDCOMMAND=/usr/bin/find
36 if [[ -z $XARGSCOMMAND ]]; then
37 XARGSCOMMAND=/usr/bin/xargs
40 if [[ -z $ECHOCOMMAND ]]; then
44 if [[ -z $SORTCOMMAND ]]; then
45 SORTCOMMAND=/usr/bin/sort
48 if [[ -z $IDENTIFYCOMMAND ]]; then
49 IDENTIFYCOMMAND=/usr/bin/identify
52 if [[ -z $WIDTH ]]; then
56 if [[ -z $IMAGEEXTENSIONS ]]; then
57 IMAGEEXTENSIONS="jpeg jpg gif png";
62 for imageext in $IMAGEEXTENSIONS; do
63 FINDIMAGESOPTIONS=$FINDIMAGESOPTIONS' -o -type f -maxdepth 1 -iname '*.$imageext' -print0'
66 FINDIMAGESOPTIONS=${FINDIMAGESOPTIONS## -o }
71 $0 [--help|--version|<path to images>]
74 displays this help screen
76 displays the version and exits
93 if [[ "$1" == "--help" || "$1" == "-h" ]]; then
98 if [[ "$1" == "--version" || "$1" == "-v" ]]; then
103 if [[ ! -d $1 ]]; then
104 echo "$1 is not a directory"
111 if ( ! $FINDCOMMAND . $FINDIMAGESOPTIONS > /dev/null 2>/dev/null ); then
112 echo "$1 does not contain any images. Quitting."
116 if [ ! -d icons ]; then
119 echo "$1 already contains an icons folder, stopping"
123 $FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 --replace $CONVERTTOOL -resize $WIDTH '{}' 'icons/{}'
125 cat <<END > index.html
126 <?xml version="1.0"?>
127 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "xhtml11.dtd">
128 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
130 <title>${TITLE}</title>
131 <link rel="stylesheet" href="style.css" type="text/css" />
137 $FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 --replace $ECHOCOMMAND {} |$SORTCOMMAND -g | sed -e 's#^./\(.*\)$#<div class="thumbnail"><a href="\1"><img src="icons/\1" /></a></div>#' >> index.html
139 cat <<END >> index.html
147 for imageext in $IMAGEEXTENSIONS; do
148 if ( ls "*.$imageext" > /dev/null 2>/dev/null ); then
149 TEMPMAX=$($IDENTIFYCOMMAND *.$imageext | grep "Geometry:" | sed -r 's#^.*Geometry:.*?[0-9]+x([0-9]+)\+.*$#\1#' | $SORTCOMMAND -g -r | head -n 1)
150 if [[ $TEMPMAX -gt $MAXHEIGHT ]]; then
159 cat <<END > style.css
163 font-family: sans-serif;
172 height: ${MAXHEIGHT}px;