Fix the photos taken by your Jolla phone (EXIF date/time, rename, rotate)

If you take a photo with your Jolla phone, the date and time is not saved in the EXIF data. I like to have these data stored in my pictures, so they can easy be renamed. I wrote a script to add the date and time to the EXIF data based on the timestamp on the filesystem.

The script does the following:

  • Add the EXIF timestamp according to the filesystem timestamp
  • Renames the photo like YYYY-mm-dd_HH-MM-SS
  • Rotates the photo correctly

Here is the script:

#!/usr/bin/env bash
<code lang="bash">

set -o errexit
set -o nounset
set -o pipefail

<code lang="bash">

DATEFORMAT=”%Y-%m-%d_%H-%M-%S”

<code lang="bash">

print_help(){
cat << EOI Usage: fixjollaphotos file [files …] This scripts does the following for your pictures taken by your Jolla phone: * Add the EXIF timestamp according to the filesystem timestamp * Renames the photo like YYYY-mm-dd_HH-MM-SS * Rotates the photo correctly The tools exiftool and jhead must be installed. EOI } check_dependencies(){ FAIL=0 for tool in $@ do if ! hash “$tool” &> /dev/null
then
echo “The tool $tool does not exist.”
FAIL=1
fi
done
if [[ “$FAIL” == 1 ]]
then
exit 1
fi
}

<code lang="bash">

fix_photo(){
echo -n Fixing “$file -> ”

<code lang="bash">

touch –reference=”$file” $file.savedate
# Add dummy timestamp, so we can it modify later
exiftool -“DateTimeOriginal=1984:05:23 13:37:42” “$file” &> /dev/null
touch –reference=”$file.savedate” $file

<code lang="bash">

# Set EXIF timestamp to the file timestamp
jhead -dsft “$file” &> /dev/null
rm “$file.savedate”

<code lang="bash">

# Correct timezone (Timestamp of file is UTC)
TIMEOFFSET=”$(date +%:z)”
jhead -ta${TIMEOFFSET} “$file” &> /dev/null

<code lang="bash">

# Rotate the photo
jhead -autorot “$file” &> /dev/null

<code lang="bash">

# Rename the file, print new filename and OK
jhead -nf$DATEFORMAT “$file” | awk ‘{ ORS=””; print $NF }’
rm “${file}_original”

<code lang="bash">

echo ” [OK]”
}

<code lang="bash">

main(){
check_dependencies jhead exiftool

<code lang="bash">

for file in “$@”
do
fix_photo “$file”
done
}

 
main "$@"

The script can also be found in my Scripts GitHub repository: fixjollaphotos.

Example:

$ fixjollaphotos Test/20160724_001.jpg
Fixing Test/20160724_001.jpg -&gt; Test/2016-08-25_16-37-12.jpg [OK]

After that, the photo has the correct EXIF date and time, is rotated correctly and renamed nicely. Simple, but very useful! ­čÖé

Leave a Comment