Skip to content

Instantly share code, notes, and snippets.

@ilyaevseev
Created February 12, 2015 01:33
Show Gist options
  • Save ilyaevseev/1aff60ab757299b81de2 to your computer and use it in GitHub Desktop.
Save ilyaevseev/1aff60ab757299b81de2 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Generate index page and thumbnail pictures
# for all GIF/JPG/PNG/... stuff in current directory.
#
THUMBDIR=thumbnails
THUMBSIZE=160x120
INDEX=index.html
INDEX0=index.inc
COLUMNS=5
workdir=$PWD
title=$(basename $workdir)
mkdir -p $workdir/$THUMBDIR
/bin/rm -f $workdir/$THUMBDIR/*
echo "<html>
<head>
<title>$title</title>
</head>
<body>
<h1>$title</h1>
" > "$workdir/$INDEX"
[ -r "$workdir/$INDEX0" ] && cat "$INDEX0" >> "$INDEX"
echo "<p>
<table width='100%'>
" >> "$workdir/$INDEX"
colnum=0
nextcol() {
if test $colnum -ge $COLUMNS; then
echo "</tr>" >> $INDEX
colnum=0
fi
colnum=$((1+$colnum))
[ $colnum = 1 ] && echo "<tr>" >> $INDEX
}
olddir=$PWD; cd $workdir
for f in *.jpg *.gif *.png *.bmp *.JPG *.GIF *.PNG *.BMP; do
[ -e "$f" ] || continue
nextcol
convert -size $THUMBSIZE "$workdir/$f" -resize $THUMBSIZE "$workdir/$THUMBDIR/$f"
echo "<td align='center'><a href='$f'><img src='$THUMBDIR/$f'></a></td>" >> $INDEX
done
for f in *.mpg *.avi *.mov *.MPG *.AVI *.MOV; do
[ -e "$f" ] || continue
nextcol
# echo "<td align='center' valign='center'><a href='$f'>Movie</a><br/>("$(stat -f '%z' $f)" bytes)</td>" >> $INDEX
echo "<td align='center' valign='center'><a href='$f'>Movie</a><br/>("$(stat -c '%s' $f)" bytes)</td>" >> $INDEX
done
cd $olddir
[ $colnum -ge $COLUMNS ] && echo "</tr>" >> $INDEX
echo "</table>
</p>
<p>Generated at "$(LANG=en date)"
</body>
</html>" >> "$workdir/$INDEX"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment