Improved improved GPS removal

October 22nd, 2010

I updated my jpeg geotag-removal script to recurse subdirectories. With that came the requirement to filter out irelevant files (not jpeg, no EXIF information). Below is the new script. I hope you find it useful:
#!/bin/bash
# Will remove non-essential EXIF from a jpeg while retaining Date/Time value.
# Use it to remove GPS information from pictures I want to put on the internet.
 
# Created Wed Aug 11 18:43:03 PDT 2010
 
# For handling spaces. See:
# http://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
 
for img in $@; do
 
    file_type=`file -b $img`
    file_type=${file_type:0:15}
 
    if [ -d "$img" ]; then
        echo "$img" is a directory - recursing
    $0 "$img/*"
 
    elif [ $file_type == "JPEG image data" ]; then
        # Grab the original date/time
        DT=`jhead "$img"|grep 'Date/Time'`
 
        # If the date information started out
        # blank, trying to tack it back on
        # will result in an error
        if [ "$DT" == '' ]; then
            continue;
        else
 
            # Current format: " Date/Time : yyyy:mm:dd hh:mm:ss"
            # jhead requires: yyyy:mm:dd-hh:mm:ss
            DT=${DT:15:25}-${DT:25}
 
            # Strip non-essential information
            jhead -purejpg "$img"
 
            # Put the date/time back
            jhead -mkexif -ts$DT "$img"
 
        fi
    else
        echo "$img" is not a JPG - ignoring $file_type
    fi
done

Tags: ,

Comments are closed.