Various scripts and snippets for working with photos in Linux. These may break things -- read the scripts and program manual pages before using. That's what I do.

Secret directory name

Secret dir name is used on a web server where directory traversal is prohibited by default, so users need to know the link to -- say -- photos of an event. They get this link through email.

$ mkdir someevent.$(pwgen -s 10 1)

Thumbnails

$ for f in [DdGgPpIi12]*_*.[Jj][Pp][Gg]; \
do echo $f; convert $f -resize 1080x960 web_$f; done;

PPM's (Panasonic RAW format) to jpg's

$ for f in p*ppm; do convert $f $(basename $f .ppm)_orig.jpg; done

Turn photos according to included exif information

$ exifautotran [DdGgPpIi12]*_*.[Jj][Pp][Gg]

Thumbnail image for certain video files

$ for f in *_*.[MmAa][TtPpVv][Ss4Ii]; \
do echo "$f" && \
ffmpeg -y -itsoffset -1  -i "$f" -vcodec mjpeg -vframes 1 \
-an -f rawvideo -s qqvga "web_$f.JPG" 2> /dev/null ; \
done

HTML page gallery of images and videos in current directory

Requires thumbnails for each photo and video file.

$ printf '<html><body>\n' > index.html && \
printf '<META http-equiv=Content-Type content="text/html; charset=UTF-8">\n' \
>> index.html && \
for f in [DdGgPpIiMm102]*_*.[MmJjAa][TtPpVv][Ss4GgIi]; \
do if [ -e $(basename $f .JPG) ]; then \
echo '<a href="'$(basename "$f" .JPG)'">'" \
<img src=\"web_$f.JPG\" ></a>" >> index.html ; \
elif [ -e $(basename $f .jpg).jpg ]; then \
echo '<a href="'$(basename "$f" .jpg).jpg'">'" \
echo "$f" \
<img src=\"web_$f\" ></a>" >> index.html ; \
elif [ -e $(basename $f .JPG).MOV ]; then \
echo '<a href="'$(basename "$f" .JPG)'.MOV">'" \
<img src=\"web_$f\" ></a>" >> index.html ; \
elif [ -e web_$(basename $f .AVI).JPG ]; then \
echo '<a href="' "$f" '">' \
"<img src=\"web_$(basename $f .AVI).JPG\" ></a>" >> index.html ; \
elif [ -e web_$(basename $f .mp4).JPG ]; then \
echo '<a href="' "$f" '">' \
"<img src=\"web_$(basename $f .AVI).JPG\" ></a>" >> index.html ; \
elif [ -e $(basename $f .AVI).THM ]; then \
echo '<a href="' "$f" '">' \
"<img src=\"$(basename $f .AVI).THM\" ></a>" >> index.html ; \
elif [ -e web_$(basename $f .AVI).JPG ]; then \
echo '<a href="' "$f" '">' \
"<img src=\"$(basename $f .AVI).JPG\" ></a>" >> index.html ; \
else echo \<a href=\"$f\"\>\<img src=\"web_$f\"\>\<\/a\> >> index.html ; \
fi; \
done ; echo "</html></body>" >> index.html

Panasonic photos and videos to index.html, OLD STUFF

$ echo "<html><body>" > index.html && for f in p*jpg; do if [ -e $(basename $f .jpg).mov ];  then echo \<a href=\"$(basename $f .jpg).mov\"\>\<img src=web_$f \>\<\/a\> >> index.html ; else  echo \<a href=\"$f\"\>\<img src=web_$f \>\<\/a\> >> index.html ; fi; done ; echo "</html></body>" >> index.html

One fast way to index.html, OLD STUFF

$ echo "<html><body>" > index.html && for f in 320*jpg; do echo \<img src=$f \> >> index.html ; done && echo "</html></body>" >> index.html

index.html template with titles and comments for photos

$ echo "<html><body><center><p><b>Otsikko</b></p>" > index.html && for f in *jpg *JPG; do echo \<img src=$f \>\<p\>kommentti\</p\> >> index.html ; done && echo "</center></html></body>" >> index.html

Better way to link thumbnails to the original photo or video, OLD STUFF

$ echo "<html><body>" > index.html && for f in img*jpg IMG*JPG; do if [ -e $f ]; then echo \<a href=\"$f\"\>\<img src=web_$f \>\<\/a\> >> index.html ; fi ; done ; for f in mvi*.avi MVI*.AVI; do if [ -e $f ] ; then echo \<a href=\"$f\"\>\<img src=$(basename $f .avi).thm \>\<\/a\> >> index.html ; fi ; done ; echo "</html></body>" >> index.html

Try to create valid HTML, didn't work and looks uggly, OLD STUFF

$ echo "<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><body>" > index.html && for f in img*jpg; do if [ -e $f ]; then echo \<a href=\"$f\"\>\<img src=web_$f \>\<\/a\> >> index.html ; fi ; done ; for f in mvi*.avi; do if [ -e $f ] ; then echo \<a href=\"$f\"\>\<img src=$(basename $f .avi).thm \>\<\/a\> >> index.html ; fi ; done ; echo "</html></body>" >> index.html

Add copyright and some banner to the corner of each image

$ for f in *.jpg; do echo $f; convert $f -pointsize 18 -gravity NorthEast -fill gray -annotate 0 '� John Doe' - | composite -dissolve 60 -gravity         SouthEast some_small_logo.gif - - | composite -dissolve 60 -gravity South       some_logo.png  - - | composite -dissolve 60 -gravity SouthWest     some_other_logo.gif - web/$( basename $f _tagged.jpg ).jpg ; done