Skip to content

Instantly share code, notes, and snippets.

@asdkant
Last active March 10, 2019 02:17
Show Gist options
  • Save asdkant/0d459d0f5f4160043c9e24277a065e9e to your computer and use it in GitHub Desktop.
Save asdkant/0d459d0f5f4160043c9e24277a065e9e to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Author: Ariel Kanterewicz <ariel@aknt.com.ar>
#
# Why this exists:
# Because I had an archive of RAW files of old pictures (all of them CR2 files),
# and the host was complaining (rightly so) that it was just a bunch of files
# dumped there instead of a proper web page.
#
# What this does:
# 1) loop over the .CR2 files in the current directory, and for every file:
# a) extract the JPEG preview using exiftool, save it to a file
# b) resize the JPEG to 400 pixels on the longer side
# c) print an <a> tag linking to the CR2 file, with an <img> tag inside
# showing the JPEG (a lot of these make a thumbnail gallery that your
# browser WILL read as I intend, even if it's technically not correct HTML)
#
# This is a quick and dirty hack but it works and shows examples of:
# - bash loops
# - exiftool usage
# - imagemagick usage
# - basic HTML tags
# - some nifty string manipulation stuff in bash that I don't recall the name of
#
# And that's why I'm sharing this with the world :-D
for i in *CR2; do
exiftool -b -PreviewImage $i > ${i%.*}.JPG
convert ${i%.*}.JPG -resize 400x400 ${i%.*}.JPG
echo '<a href="'$i$'"><img src="'${i%.*}.JPG'"></a>' >> index.html
echo $i "->" ${i%.*}.JPG
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment