Created
September 10, 2015 13:49
-
-
Save wulff/10696c93cfb4e2d84297 to your computer and use it in GitHub Desktop.
A simple Bash script for converting 360˚ artifact images from the National Museum of Denmark to animated GIFs. Requires ImageMagick.
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 | |
# You can use this script to create animated GIFs from the "rotationsbilleder" | |
# provided by the National Museum of Denmark. | |
# | |
# usage: natmus2gif.sh [asset id] [width in pixels] | |
# | |
# example: ./natmus2gif.sh 11006 480 | |
# | |
# This will create a 480px wide animated GIF from the pictures referenced on | |
# http://samlinger.natmus.dk/DO/11006. | |
# bail on errors | |
set -e | |
# regular expression to match integers | |
numeric='^[0-9]+$' | |
# get asset id | |
id=$1 | |
if ! [[ $id =~ $numeric ]]; then | |
echo "error: you must supply a numeric item id" >&2 | |
exit 1 | |
fi | |
# get desired width in pixels | |
width=$2 | |
if ! [[ $width =~ $numeric ]]; then | |
echo "error: you must supply a numeric width" >&2 | |
exit 1 | |
fi | |
# get the page and extract the frame IDs | |
echo "fetching html" | |
images=$(curl -s "http://samlinger.natmus.dk/DO/$id" | \ | |
/usr/bin/grep -E -o " images:(.*?);" | \ | |
/usr/bin/grep -E -o "/DO.*?/1000") | |
# download the individual frames to the current directory | |
frames='' | |
while read -r line; do | |
collection=$(echo "$line" | cut -d"/" -f2 | tr '[:upper:]' '[:lower:]') | |
file=$(echo "$line" | cut -d"/" -f3) | |
echo "fetching $file"; | |
curl -s "http://samlinger.natmus.dk/DO/$file/image/$width" > "./$file.jpg" | |
frames="$frames $file.jpg" | |
done <<< "$images" | |
echo "creating gif from frames" | |
convert -delay 60 $frames -layers OptimizeFrame +map -loop 0 -colors 128 \ | |
"natmus-$collection-$id.gif" | |
echo "removing source files" | |
rm $frames |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment