How to recover metadata in processed photos
December 22, 2020
Photo metadata is information that is contained within the image file, it can include GPS coordinates, information about the time of shooting, about the settings of the camera and the camera itself, as well as other information.
After processing in a photo editor, meta information may be lost. This tutorial will show you how to get meta information back in photos after you edit them in a photo editor.
This method allows you to return metadata both in one image and to recover metadata for a large number of images using batch processing. But there is a condition – you must keep the original photo with metadata, since information will be copied from it and transferred to the image, where the metadata is lost.
We will use the ExifTool program that can copy metadata from one photo to another. ExifTool works even on Windows, and in Linux this program is available in the standard repositories of almost all distributions, that is, it is enough to install the exiftool package.
Start by backing up your images (or directories if you want to restore metadata for an entire folder) – just in case.
An example of a command that transfers metadata from file a.jpg to file b.jpg:
exiftool -TagsFromFile a.jpg b.jpg
Where:
- a.jpg is the original snapshot, which still has metadata
- b.jpg is a snapshot after processing in a photo editor, as a result of which the metadata was erased
Let's assume that some of the original photos have been processed and placed in a new folder. These snapshots have lost metadata. How can I recover metadata from processed snapshots?
If files with metadata and processed files without metadata are named the same, then the following command should do what I need:
exiftool -TagsFromFile /DIRECTORY/SOURCE/FILES/%f.%e /DIRECTORY/DIRECTORY/FILES/
For example, my test command:
exiftool -TagsFromFile /mnt/disk_d/Share/TestPicsOrig/%f.%e /mnt/disk_d/Share/TestPics/
did the following:
- for each image from the /mnt/disk_d/Share/TestPics/ folder, a pair was found in the /mnt/disk_d/Share/TestPicsOrig/ folder with exactly the same name and extension.
- then metadata was taken from the image in the /mnt/disk_d/Share/TestPicsOrig/ folder and written to the image in the /mnt/disk_d/Share/TestPics/ folder
- all files that were modified were backed up in the /mnt/disk_d/Share/TestPics/ folder with names ending in "_original".
In fact, you don't need to keep a second copy of the images if you only want metadata in them. The ExifTool program allows you to create files containing only metadata – later you can restore information from them to processed photos. To create files with metadata for all images in /FOLDER/WITH/PHOTOS/ and save them in /FOLDER/WITH/METADATA/ use a command like:
exiftool -a -ext JPG -o /FOLDER/WITH/METADATA/%f.exif /FOLDER/WITH/PHOTOS/
To restore metadata to processed images from files containing only metadata, run a command like this:
exiftool -TagsFromFile /FOLDER/WITH/METADATA/%f.exif /FOLDER/WITH/PHOTOS/
Don't confuse the options – the first command uses the -o option, which denotes the output folder/file, and the second command uses the -TagsFromFile option, which denotes the folder/file from which the metadata should be taken.
If you do not want backups of images to be saved during processing with the string "_original" added to their names, then use the "-overwrite_original" option. This option, when writing information to an image, overwrites the original FILE (instead of saving it by adding "_original" to the filename). Note: This option should only be used if you already have separate backups of your image files. Overwriting is done by renaming the temporary file to replace the original. This will delete the original file and replace it with the edited version in one operation. Combined with -o, this option causes the original file to be deleted if the output file was written successfully (that is, the file is moved, not copied).
Related articles:
- How to find the place where a photo was taken without third-party services (80.1%)
- Basics of launching and using command line utilities in Windows (66.1%)
- All about MAC addresses: what are they for, how to view and find out the manufacturer by MAC address (53.8%)
- How to boot into VirtualBox from USB (53.8%)
- GIMP copies not all layers (SOLVED) (53.2%)
- How to connect your phone to the Internet using another phone's Bluetooth (RANDOM - 50%)