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

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

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

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
}

fix_photo(){
    echo -n Fixing "$file -> "

    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

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

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

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

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

    echo " [OK]"
}

main(){
  check_dependencies jhead exiftool

  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 -> 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 Reply

Your email address will not be published. Required fields are marked *