0

I've been coming up with a script to remove any EXIF/IPTC/XML meta data from a JPEG file that equals 'OLYMPUS DIGITAL CAMERA'. For those who aren't aware, Olympus cameras set this attribute in all photos with no option to turn it off. Worse still, although I have set up a Lightroom preset to remove it on import, or while editing existing images, there seems to be a bug in recent LR releases that still embed the attribute in the ImageDescription, Caption-Abstract and Description when exporting an image to JPEG.

So like many Olympus users, I want it banished for good and I wrote a very simple bash script to do so. It's designed primarily to run on my QNAP NAS but could easily be modified to work in different environments. It searches for any instance of "OLYMPUS DIGITAL CAMERA" in the output of exiftool on a particular image and then deletes that attiobute.

#!/usr/bin/env bash
IFS=$'\n'; ## Handle spaces in file paths/names
directory="/share/CE_CACHEDEV1_DATA/homes/admin/Images/Final Albums/"
exiftool="/share/CE_CACHEDEV1_DATA/.qpkg/Entware/bin/exiftool"
find="/opt/bin/find"

for f in $($find "$directory" -type f -iname '*.jp*g');
do
    #echo "$f"
    for field in $($exiftool -s "$f" | grep "OLYMPUS DIGITAL CAMERA" | awk -F: '{ print $1 }' | sed 's/ *$//g');
    do
        echo "Removing $field on $f"
        $exiftool -overwrite_original -"$field"= "$f"
    done
done

The only problem with this is that it's quite slow. Any call to exiftool seems to take 0.5s and so I wanted to improve efficiency by removing all attributes in one go, rather than looping round each matching attribute and removing them one by one. So this is version 2 of the script.

#!/usr/bin/env bash
IFS=$'\n'; ## Handle spaces in file paths/names
directory="/share/CE_CACHEDEV1_DATA/homes/admin/Images/Final Albums/"
exiftool="/share/CE_CACHEDEV1_DATA/.qpkg/Entware/bin/exiftool"
find="/opt/bin/find"
for f in $($find "$directory" -type f -iname '*.jp*g');

do
    #echo "$f"
    fieldstring=''
    for field in $($exiftool -s "$f" | grep "OLYMPUS DIGITAL CAMERA" | awk -F: '{ print $1 }' | sed 's/ *$//g');
    do
        fieldstring="${fieldstring}-$field= "
    done
    echo $fieldstring
    $exiftool -overwrite_original $fieldstring $f
done

The problem is that it only appears to remove one attribute at a time. The output of $fieldstring is:

-ImageDescription= -Caption-Abstract= -Description=

But I've also tried surrounding the tags to remove with single quotation marks and double, neither helped.

I thought perhaps that's a limitation of eximtool. But I wrote another script which simply wipes the 3 main attributes (ImageDescription, Caption-Abstract and Description) without any testing for what they contain and that works fine!

#!/usr/bin/env bash
IFS=$'\n'; ## Handle spaces in file paths/names
directory="/share/CE_CACHEDEV1_DATA/homes/admin/Images/Final Albums/"
exiftool="/share/CE_CACHEDEV1_DATA/.qpkg/Entware/bin/exiftool"
find="/opt/bin/find"
for f in $($find "$directory" -type f -iname '*.jp*g');
do
    echo "$f"
    $exiftool -overwrite_original -"Description"= -"Caption-Abstract"= -"ImageDescription"= "$f"
done

So I'm fairly sure this is one of those stupid, right-in-front-of-your-nose mistakes I've made but after 2 hours of trying to figure it out, I'm at a loss. Can anyone spot a stupid mistake? I've output $fieldstring and it looks OK to me so I think it's a bash script thing that I'm missing, hence posting here!

Many thanks!

1
  • 1
    Sorry, I removed the shebang and initial variable set up on the second 2 scripts just for simplicity. I've edited the post now. Jan 4, 2022 at 9:12

1 Answer 1

0

I've taken your requirement and written a fresh script. You may want to customise the set -- . so that the dot is replaced by the default path to the images. Or you can provide the images directory on the command line

#!/usr/bin/env bash
#
export PATH=/opt/bin:$PATH           # Prefer commands from Entware

[[ $# -eq 0 ]] && set -- .           # Replace . with default path to source of images
unwanted='OLYMPUS DIGITAL CAMERA'    # phrase to match and remove

find "$@" -type f \( -iname '*.jpg' -o -iname '*.jpeg' \) -print |
    while IFS= read -r file
    do
        # Get list of fields containing the unwanted phrase
        fields=($(exiftool -s "$file" | awk -v x="$unwanted" '$0 ~ x {print $1}'))

        # Skip files with no issues
        [[ ${#fields[@]} -eq 0 ]] && continue

        # Convert fields to exiftool parameters
        exifargs=()
        for field in "${fields[@]}"
        do
            exifargs+=("-$field=")
        done

        # Apply the conversion
        echo "Removing ${fields[@]} from: $file"
        echo exiftool -overwrite_original "${exifargs[@]}" "$file"
    done

# Done
exit 0

Remove the echo from echo exiftool when you're happy it's going to do what you want.

We're use bash arrays here. For example fields is an array containing the list of EXIF key names that contain the text OLYMPUS DIGITAL CAMERA, and exifargs is the corresponding list of arguments to exiftool that remove the field values. We could have generated exifargs directly with awk but it seemed easier to show what was going on with the two steps.

3
  • Thanks for taking the time to write an alternative script. I think you've missed out using the variable "unwanted". Easy enough fix of course. But to be honest, I've just realised that if exiftool doesn't need to make any changes, it doesn't touch the file in question. I was worried that if I ran my third script in the original post, it would update all files and my backup script for my image folder would want to sync all files. That doesn't appear to be the case so I think I'll stick with that. It just bothered me that I couldn't figure out why my script didn't work! Jan 4, 2022 at 10:31
  • P.S. There's a lot I can learn from your script though and actually could come in handy in case there are other fields I want to get rid of, rather than just ImageDescription, Caption-Abstract and Description. Thanks again! Jan 4, 2022 at 10:42
  • @willdashwood thank you for spotting the unused variable. I've attached it to the awk now like I'd intended in the first place Jan 4, 2022 at 10:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .