Skip to content

Instantly share code, notes, and snippets.

@ftf
Last active December 15, 2015 10:49
Show Gist options
  • Save ftf/5248154 to your computer and use it in GitHub Desktop.
Save ftf/5248154 to your computer and use it in GitHub Desktop.
#!/bin/bash
EV_DIRECTORY="/Users/manu/Pictures/daily"
EV_BASE=`basename $EV_DIRECTORY`
function everyday_newpics {
# go to where the deed is done
cd $EV_DIRECTORY
# echo some information about the process
LASTIMPORT=`exiftool "-DateTimeOriginal" $(ls -1r [0-9]*.JPG | head -n1) | awk ' { print $4 " " $5 }'`
IMPORTCOUNT=`ls -1 IMG*.JPG | wc -l`
date
echo "Last import on: "$LASTIMPORT
echo "To be imported: "$IMPORTCOUNT
# backup the complete directory before proceeding, preserving timestamps
cp -Rp . ../$EV_BASE.old
# writes the "File last modified" timestamp into all Date-related EXIF-tags
exiftool "-FileModifyDate>AllDates" IMG*.JPG
# the command above changes said "File last modified" timestamp - so now we reset it, using the EXIF date we just set
exiftool "-FileModifyDate<DateTimeOriginal" IMG*.JPG
# renames the files in a way that sorting by name gives the correct order, e.g. 20130322_1930.JPG (in case of duplicates it adds a counter)
exiftool -d %Y%m%d_%H%M%%-c.%%e "-Filename<DateTimeOriginal" IMG*.JPG
# exiftool saves the originals when modifying images. we have a backup anyway, but just to be sure, let's store them anyway…
mkdir -p old
mv *original old/
# check results
open .
open ../$EV_BASE.old
}
function everyday_collage {
# go to where the deed is done
cd $EV_DIRECTORY
echo "Creating a collage with ${1} pictures in each row…"
echo "Cutting ${2} pixels from each input picture in height, final width ${3} pixels"
# create the montage. -geometry is used to specify the size at which each source picture will be used.
montage *.JPG -tile ${1}x -geometry 240x320+0-${2} collage.png;
convert collage.png -resize ${3}x collage.png
}
function everyday_video {
# go to where the deed is done
cd $EV_DIRECTORY
echo "Creating a video with ${1} pictures per second. This will take a while…"
# sadly this conversion seems necessary for the pictures working with ffmpeg. takes a while.
if [ -z "$2" ]; then
for f in *.JPG; do convert $f "$f.png"; done
else
for f in *.JPG; do temp_date=`identify -format '%[EXIF:DateTimeOriginal]' $f | cut -d" " -f1 | sed -e 's/\:/-/g'`;convert -gravity NorthEast -stroke '#000C' -strokewidth 5 -pointsize 16 -font MenloplusB -annotate +5+5 "$temp_date" -stroke none -pointsize 16 -font MenloplusB -fill white -annotate +5+5 "$temp_date" $f "$f.png"; done
fi;
# rename sequentually, use -n for preview
rename '$_ = sprintf "%04d.png", ++$::count, $_' *.png
# bitrate is the last number, currently 2345
ffmpeg -f image2 -r ${1} -i %04d.png -vcodec libx264 -preset slow -threads 0 -pix_fmt yuv420p -b:v 2345k everyday.mp4
if [ -z "$3" ]; then
rm *.png
fi;
}
# Saves exif geo data from all images in thepathofpics into out.kml
# exiftool -r -if '$gpslatitude' -p kml.fmt -d %Y-%m-%dT%H:%M:%SZ /the/path/of/pics > out.kml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment