How to preserve exif metadata in images in Linux

  • Post author:
  • Post last modified:August 19, 2023
  • Reading time:3 mins read

1.0 Exif metadata not preserved by image editing program

Problem: After an image is developed and edited by image editing software and saved in a format like JPEG, it does not have the Exif metadata.

2.0 Solution

Surprisingly, quite a few image editing programs do not preserve the Exif metadata of images and attempts to read Exif get outputs like this.

$ exiv2 DSC_6683.jpg 
File name       : DSC_6683.jpg
File size       : 23652200 Bytes
MIME type       : image/jpeg
Image size      : 6024 x 4024
DSC_6683.jpg: No Exif data found in the file

But, no worries, you can simply copy the Exif data from the camera raw file to the developed JPEG using the exiftool command. For example,

$ exiftool -tagsFromFile DSC_6683.NEF DSC_6683.jpg
    1 image files updated
$ exiftool -Orientation=1 -n DSC_6683.jpg
    1 image files updated
$ exiv2 DSC_6683.jpg 
File name       : DSC_6683.jpg
File size       : 23688740 Bytes
MIME type       : image/jpeg
Image size      : 6024 x 4024
Camera make     : XXXXX CORPORATION
Camera model    : XXXXX X999
Image timestamp : 2017:10:07 17:40:55
Image number    : 
Exposure time   : 1/30 s
Aperture        : F7.1
Exposure bias   : 0 EV
Flash           : 
Flash bias      : 
Focal length    : 24.0 mm (35 mm equivalent: 24.0 mm)
Subject distance: 
ISO speed       : 125
Exposure mode   : Manual
Metering mode   : Multi-segment
Macro mode      : 
Image quality   : RAW    
Exif Resolution : 
White balance   : PRESET1     
Thumbnail       : None
Copyright       : John Doe
Exif comment    : 
$ 

The second exiftool command sets the image orientation as 1, which is horizontal. As we are writing Exif data for the final processed image, there is no point in writing the orientation of the original image recorded by the camera.

You can delete some tags. For example, to delete the shutter speed and aperture, the command is,

$ exiftool -ExposureTime= -FNumber= DSC_6683.jpg

And, to get the tag names for using as parameters in the exiftool command, run

$ exiftool -s DSC_6683.jpg
ExifToolVersion                 : 10.10
FileName                        : DSC_6683.jpg
Directory                       : .
FileSize                        : 19 MB
FileModifyDate                  : 2017:11:28 17:21:48+05:30
FileAccessDate                  : 2017:11:28 17:21:54+05:30
FileInodeChangeDate             : 2017:11:28 17:21:48+05:30
FilePermissions                 : rw-rw-r--
FileType                        : JPEG
FileTypeExtension               : jpg
MIMEType                        : image/jpeg
JFIFVersion                     : 1.01
...

The left column gives the tag names which you can use as parameters in the exiftool command.

Share

Karunesh Johri

Software developer, working with C and Linux.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments