Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes Monday through Friday.


hpr3564 :: Removing EXIF data from an image

An image might reveal data you want to keep private

<< First, < Previous, , Latest >>


Hosted by Dave Morriss on 2022-03-31 is flagged as Explicit and is released under a CC-BY-SA license.
image,Exif,exiftool,GraphicsMagick,orientation.
Listen in ogg, spx, or mp3 format. | Comments (4).

general.

Introduction

I’m writing a script to process image files sent in by HPR hosts with their shows. One of the things the script does is to strip Exif metadata from such images. That’s because this metadata may contain details that could identify the creator of the image - their camera, their location, and other things. Many people will be alert to this, but in case anything slips through it seems a courtesy to anonymise images sent to HPR.

As I was implementing this I realised that one piece of Exif data: 'Orientation', can’t just be removed. Sometimes images are created with a particular orientation by the camera but are written with an Exif orientation setting that shows another orientation. If this is just removed the image might be shown wrongly.

This short episode describes the journey I had learning about this issue and finding how to get round it.

The Problem

A show was sent in early March 2022 which had three images with orientation values in the Exif metadata. They had apparently been taken with one orientation but were being rotated for viewing.

I later discovered that the orientation setting can be viewed with the exiftool command:

$ exiftool -orientation testimage.jpg
Orientation                     : Rotate 90 CW

You can find information about the Orientation tag on the ExifTool web site.

The actual image in this case is rotated 90° anti-clockwise (the top of the image is to the left) and this needs to be reversed. The setting 'Rotate 90 CW' causes it to be displayed after rotating 90° in the clockwise direction. The actual value for this setting is 6.

The problem is that removing all the Exif data causes such an image to revert to its raw state as explained below.

Investigation

Demonstration

It took me a little while to understand this problem because I couldn’t find a good explanation of what was going on.

I found a repository on GitHub which would take a picture and generate all of the possible Exif orientations from it. I used it to generate pictures from one (a thumbnail) I used in an old HPR show. Here’s the original picture with an orientation setting of 6 (Rotate 90 CW), and then with the Exif metadata removed.

Original image with orientation 6
Original image with orientation 6

Same image with Exif stripped
Same image with Exif stripped

Methods used to fix this

I found and installed some tools:

  • jpegexiforient - reads or writes the Exif Orientation Tag
  • exifautotran - transforms Exif files so that Orientation becomes 1
  • jpegtran - lossless transformation of JPEG files

Note that these only operate on JPEG images.

The exifautotran tool is a shell script that uses jpegexiforient to find the orientation and jpegtran to undo whatever rotation (or other transformation) has been defined.

Reading the exifautotran script helped me understand all of this, but I did not use these tools in the end.

In the script I had written to manage images I also needed to do other image operations:

  • interrogate the image to find its size to determine whether a thumbnail was needed
  • make a thumbnail if necessary

To do this I had started to use the GraphicsMagick package.

This package actually caters for the orientation transformation I wanted to perform and can handle many image types, not just JPEG.

The technique is to use the command 'gm convert' with two options:

  • -strip - remove all profiles and text attributes from the image
  • -auto-orient - orient (rotate) the image so it is upright; adjusts the image orientation so that it is suitable for viewing

Example:

gm convert -strip -auto-orient sideways_pic.jpg normal_pic.jpg

Running this on the images in question removed the Exif orientation after having rotated the pixels of the image to the 'Horizontal (normal)' state.

Conclusion

I have modified my picture management script to use this technique, and so far it seems to do the job perfectly. It has to be admitted that images with Exif orientation metadata are rare though.

The GraphicsMagick documentation indicates that the transformations needed to generate an upright image could cause problems with some images, so we will be alert to any issues. For the moment, it looks as if the problem is largely solved.

Personally, I gained several things from this journey of discovery:

  • I ended up understanding images a bit better.
  • Using exiftool to examine these images helped me to understand the power of this tool1.
  • I also discovered that if opened the example image with Gimp it spotted the orientation issue and asked if I wanted it to perform the transformation discussed above.
  • I installed a KDE image tool called ShowFoto and it also reported the fact that the image existed in two forms, in the same way, and allowed Exif editing.

  1. For the record, removing all Exif data with exiftool is achieved with the command:

    exiftool -all= image.jpg
    ↩︎

Comments

Subscribe to the comments RSS feed.

Comment #1 posted on 2022-03-31 12:24:00 by Some Guy On The Internet

Much Respect

I never thought about the work that goes into managing show notes and images other host submit. Wow, working to keep others anonymous is very admirable of you. A show to educate everyone on managing our data; excellent work. THANK YOU VERY MUCH!
Comment #2 posted on 2022-04-01 11:55:04 by ClaudioM

Thanks for the Application Reminder!

Big thanks for reminding me about this app. I actually used it yesterday to remove information from a picture I took for inclusion in a trouble ticket. Great little tool!
Comment #3 posted on 2022-04-01 19:04:02 by Xoke

My troubles with EXIF

We had people taking photos for profile at work. Microsoft shop, so active directory / exchange etc. If you took a photo with an apple device, it would always get the image sideways, but androids would not. It looked like apples handle the rotation differently (e.g. they save the image whichever way, but keep exif data but android rotate the image to be 'up' and save it) If you're using windows, IrfanView has command line commands for rotating (and much much more) in the i_options.txt file. That was how we fixed the issue I was also going to say what CW was but I see you figured that out :) And CCW could be Counter ClockWise if using the American version.
Comment #4 posted on 2022-04-16 12:05:04 by Kevin O'Brien

Orientation in Android

I have been processing a ton of photos from my RV trip, all taken with Android phones, and I get some with the wrong orientation. I can correct this in digikam, which is my collection management tool. When corrected, they stay correct after that.

Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Title:
Comment:
Anti Spam Question: What does the P in HPR stand for ?