-
-
Save uGeek/95c48211636b638a2a0cab8ac0c611bc to your computer and use it in GitHub Desktop.
Recursive create a gallery from all images in a directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
OLDIFS=$IFS | |
IFS=$'\n' | |
echo "Starting gallery..." | |
DIRECTORIES=$(find -type d) | |
# loop over all subdirectories | |
for d in $DIRECTORIES | |
do | |
pushd $d | |
# find all images in subdirectory | |
FILES=$(find -maxdepth 1 -type f -name "*.jpg" -o -name "*.png") | |
# create directory for thumbnails | |
mkdir -p thumbs | |
# create html page for subdirectory | |
cat > index.html << EOF | |
<html> | |
<head> | |
</head> | |
<body> | |
<h1>$d</h1> | |
<ul> | |
EOF | |
for img in $FILES | |
do | |
#create thumbnail | |
thumbimg="thumbs/thumb_`basename ${img/ /_}`" | |
if [ ! -e $thumbimg ] | |
then | |
convert -thumbnail 200 $img $thumbimg | |
fi | |
echo "Thumbnail for $img created." | |
echo "<li><a href=\"$img\">" >> index.html | |
if [[ $img =~ .*[png|jgp] ]] | |
then | |
echo "<img src=\"$thumbimg\" alt=\"$img\"/>" >> index.html ; | |
else | |
echo "$img" >> index.html ; | |
fi | |
echo "</a></li>" >> index.html | |
done | |
cat >> index.html << EOF | |
</ul> | |
</body> | |
</html> | |
EOF | |
# jump back | |
popd | |
done | |
IFS=$OLDIFS | |
echo "Gallery ready." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment