Fixing Lightroom messed up files with Exiftool (Mac)

Started by pacman, January 29, 2016, 04:00:49 PM

Previous topic - Next topic

Phil Harvey

Quote from: pacman on March 08, 2016, 02:48:45 PM
Thanks, but unfortunately it didn't work.
After running the PNG file through the command you suggested: (exiftool "-png:creationtime<mditemfscreationdate" some.png) I ended up with three additional tags compared to the original file when analyzing it (exiftool -a -G1 -s FILENAME.PNG):

[PNG]           CreationTime                    : xxxxxxx
[XMP-exif]      ExifImageWidth                  : xxxxxxx
[XMP-exif]      ExifImageHeight                 : xxxxxxx
[

I find this hard to believe.  This shouldn't happen, as the command is writing only a native PNG tag.  Are you sure you didn't do something else?  If you can reproduce this, send me the file and the exact command you used and I'll look into it.  My email is philharvey66 at gmail.com

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

pacman

You're absolutely right.
I must have been testing with some previously manipulated PNG files as I created some brand new PNG files, ran the command and found the only difference to be the addition of [PNG] CreationTime. Still, no date is displayed for the files using Preview.app in OSX.
Sorry about the confusion though.

Nevertheless I've tested a batch of PNG files with the various commands and sent your way. Fortunately Exiftool appears to be able to add an EXIF date tag to PNG files but the question is which one to add.

Phil Harvey

My concern was that ExifTool was behaving properly, which it was.

I don't have time to investigate the behaviour of other apps, but in general the support for metadata in PNG images tends to be sketchy at best.  I am actually surprised that OS X supports XMP metadata in PNG, but according the descriptions you sent it seems that it does.  So you should maybe be writing the standard XMP date/time tags (XMP-xmp:CreateDate, XMP-xmp:ModifyDate and XMP-photoshop:DateCreated) instead of the standard PNG tags as I used in my example command.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

pacman

#33
I've just experimented with numerous tags which resulted in the following (the goal being to create a date/time tag in PNG files which didn't already have them, and have those recognized by Lightroom and in Mac OSX itself -using Preview):

$ exiftool "-XMP-xmpMM:HistoryWhen<MDItemContentCreationDate" FILENAME.PNG
Preview:  failed (no date)
Lightroom: failed (no date)

$ exiftool "-XMP-xmp:MetadataDate<MDItemContentCreationDate" FILENAME.PNG
Preview:  failed (no date)
Lightroom: failed (no date)

$ exiftool "-png:CreationTime<MDItemContentCreationDate" FILENAME.PNG
Preview: failed (no date)
Lightroom: failed (no date)

$ exiftool "-XMP-Exif:CreateDate<MDItemContentCreationDate" FILENAME.PNG
Error (tag 'xmp-exif:CreateDate' does not exist)

$ exiftool "-XMP-xmp:DateTimeDigitized<MDItemContentCreationDate" FILENAME.PNG
Error (tag 'xmp-xmp:DateTimeDigitized' does not exist)

$ exiftool "-XMP-Exif:DateTimeOriginal<MDItemContentCreationDate" FILENAME.PNG
Preview: yes "Date time original" (EXIF tab) added
Lightroom: yes "Date time original" (EXIF) added
Lightroom: yes "Date created" (IPTC) added
ABFA: yes -is able to restore the OSX creation date (reads the EXIF date in order to re-write the OSX file creation date)


$ exiftool "-XMP-xmp:ModifyDate<MDItemContentCreationDate" FILENAME.PNG
Preview: yes "Date time" (TIFF tab) added
Lightroom: yes "Date time" (EXIF) added
ABFA: yes -is able to restore the OSX creation date (reads the EXIF date in order to re-write the OSX file creation date)


$ exiftool "-XMP-photoshop:DateCreated<MDItemContentCreationDate" FILENAME.PNG
Preview: yes  "Date time original" (EXIF tab) added
Lightroom: yes "Date created" (IPTC) added
ABFA: yes -is able to restore the OSX creation date (reads the EXIF date in order to re-write the OSX file creation date)

$ exiftool "-XMP-xmp:CreateDate<MDItemContentCreationDate" FILENAME.PNG
Preview: yes "Date time digitized" (EXIF tab) added
Lightroom: yes "Date time digitized" (EXIF) added
ABFA: failed -unable to restore OSX file creation date

$ exiftool "-XMP-Exif:DateTimeDigitized<MDItemContentCreationDate" FILENAME.PNG
Preview: yes  "Date time digitized" (EXIF tab) added
Lightroom: yes "Date time digitized" (EXIF) added
ABFA: failed -unable to restore OSX file creation date

...and finally, in order to compare, using Lightroom's own "Change to file's creation date" feature....
This is obviously my reference (what I want to achieve) as the files naturally show their dates within Lightroom, but also in OSX itself.
- Preview: "Date time original" (EXIF tab) added
- Preview: "Date time" (TIFF tab) added
- Lightroom: "Date time original" added
- Lightroom: "Date time" (EXIF) added
- Lightroom: "Date time" (IPTC) added
- ABFA: yes -is able to restore the OSX creation date (reads the EXIF date in order to re-write the OSX file creation date)


Conclusion from the above tests:
The following two commands appear to give a PNG file the needed tags (using the Lightroom generated date feature as a reference):

$ exiftool "-XMP-Exif:DateTimeOriginal<MDItemContentCreationDate" FILENAME.PNG
Preview: adds "Date time original" (EXIF tab) date tag
Lightroom: adds "Date time original" (EXIF) date tag
Lightroom: adds "Date created" (IPTC) date tag
ABFA: yes -is able to restore the OSX creation date (reads the EXIF date in order to re-write the OSX file creation date)

and
$ exiftool "-XMP-xmp:ModifyDate<MDItemContentCreationDate" FILENAME.PNG
Preview: adds "Date time" (TIFF tab) date tag
Lightroom: adds "Date time" (EXIF) date tag
ABFA: yes -is able to restore the OSX creation date (reads the EXIF date in order to re-write the OSX file creation date)

The final solution... maybe
Having figured out the above I'm not entirely sure it's essential to combine the two commands as files with either command appear to work as intended. But if I want to make them appear as if Lightroom added a date tag to those PNG files (the only difference being that with the Exiftool processed files the "Date created" (IPTC) tag would contain an additional timezone number after the date (i.e. 2016-03-10T09:33:51+01:00 instead of 2016-03-10T09:33:51) then the procedure appeared to be as follows:

1) $ exiftool "-XMP-Exif:DateTimeOriginal<MDItemContentCreationDate" FILENAME.PNG
2) run ABFA on the file in order to restore the OSX file creation date. Failing to do this would also fail getting the correct "Date time" date tag as it's getting its info from the file creation date (which would be changed in step 1)
3) $ exiftool "-XMP-xmp:ModifyDate<MDItemContentCreationDate" FILENAME.PNG

Is there a way I can combine both command lines in a single line?
I'm hoping there will be a way for Exiftool to re-write the OSX file creation date (I've posted about this in a separate thread suggesting the use of the "touch" command) but until then I'll be using A Better Finder Attributes (ABFA) which does the job.


Phil Harvey

Quote from: pacman on March 13, 2016, 04:32:06 PM
1) $ exiftool "-XMP-Exif:DateTimeOriginal<MDItemContentCreationDate" FILENAME.PNG
2) run ABFA on the file in order to restore the OSX file creation date. Failing to do this would also fail getting the correct "Date time" date tag as it's getting its info from the file creation date (which would be changed in step 1)
3) $ exiftool "-XMP-xmp:ModifyDate<MDItemContentCreationDate" FILENAME.PNG

Is there a way I can combine both command lines in a single line?

Yes.  You can copy as many tags as you want in a single command.

Also, you may want to add -P -overwrite_original_in_place to preserve as many of the system attributes as possible.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

pacman

#35
Thanks -that's a good point.
Experimenting a bit I came up with the following which appears to work with a folder with various files and file-types, some missing and some already containing EXIF date tags. Can you confirm if the syntax looks correct and won't touch files already containing EXIF date tags?

$ exiftool -r "-XMP-Exif:DateTimeOriginal<MDItemContentCreationDate" "-XMP-xmp:ModifyDate<MDItemContentCreationDate" -P -overwrite_original_in_place .

Actually it even keeps the OSX file creation date so I don't need to run the file(s) through ABFA afterwards unless Lightroom is used to add new keywords etc.  :)

Phil Harvey

The syntax is good, but I don't understand why you think it shouldn't touch files already containing EXIF date tags, because it will.  To do this, you could add something like: -if 'not $exif:datetimeoriginal'

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

pacman

#37
Because I read (or mis-read) [page]=3#topic-reply-list]here (page 3) that Exiftool wouldn't do anything to files already having an EXIF date tag to begin with:

QuoteOpen terminal (make sure you have Exiftool installed)
and CD to your target directory.
Then copy & paste into the command line:

exiftool -r -overwrite_original_in_place '-datetimeoriginal&ltfilemodifydate' -if '(not $datetimeoriginal or ($datetimeoriginal eq "0000:00:00 00:00:00")) and ($filetype eq "TIFF")' .

The period at the end's important. This will update every tiff in the folder so that the creation date is loaded into the metadata, if the image didn't have anything there to start with. If it did, it won't touch it. It will update your creation date to "now" though, so you'll have to go back through with something like "Finder Attirbutes' to reset the creation dates based on the exif data. (Reasoning, comma circular, see Circular Reasoning.) But it works.
If you want to get JPG,s just change the filetype to "JPG". PNG works too.

Anyway, after including the command in your previous posting it all appears to work fine (image files already containing an EXIF date aren't modified, non-image files are skipped and any image file without EXIF dates (including PNG files) get new EXIF date tags created based on the OSX file creation date), the final command being:
$ exiftool -r "-XMP-Exif:DateTimeOriginal<MDItemContentCreationDate" "-XMP-xmp:ModifyDate<MDItemContentCreationDate" -P -overwrite_original_in_place -if 'not $exif:datetimeoriginal' .

Eventually I'll be making a "drag & drop" script placed in the OSX dock so I can quickly and easily add EXIF date tags to any file or folder I suspect is missing them.
But there's a strange thing happening with a couple of my PNG files: after being processed by Exiftool they still don't show up with any dates in the Preview app (while other PNGs do). Oddly all looks fine in Lightroom (the date has indeed been added as with the normal PNG files previously missing EXIF date tags).
However, if I add (and save) a keyword within Lightroom those "stubborn" files now show their dates in Preview as well!
So I found it obvious to compare the files' tags using exiftool -a -G1 -s FILENAME.PNG, and that's what I did.

I found a "normal" PNG file to contain numerous additional tags to start with (before being processed by Exiftool) compared to the "stubborn" PNG's tags, and after Exiftool-processing they both contained (as expected, based on my Exiftool command) the following new tags:

[XMP-exif]      DateTimeOriginal   
[XMP-xmp]       ModifyDate       

... in addition to this the "stubborn" PNG also had the following tag which was't present to begin with (but already present in the "normal" PNG, though with a different value). I assume it's just a standardized tag which any EXIF-manipulating software has to include. Didn't make any difference in showing the EXIF date in Preview though:

[XMP-x]         XMPToolkit


... so the next step would be to see which additional tags were added to the "stubborn" PNG after Lightroom added a keyword to the file:

[XMP-exif]      ExifVersion                   
[XMP-xmp]       MetadataDate                   
[XMP-photoshop] DateCreated                   
[XMP-tiff]      Orientation                   
[XMP-xmpMM]     DocumentID                     
[XMP-xmpMM]     OriginalDocumentID             
[XMP-xmpMM]     InstanceID                     
[XMP-xmpMM]     HistoryAction                 
[XMP-xmpMM]     HistoryInstanceID             
[XMP-xmpMM]     HistoryWhen                   
[XMP-xmpMM]     HistorySoftwareAgent            : Adobe Photoshop Lightroom 5.7.1 (Macintosh)
[XMP-xmpMM]     HistoryChanged                 
[XMP-dc]        Format                         
[XMP-dc]        Subject                       
[XMP-crs]       RawFileName                   
[XMP-lr]        HierarchicalSubject

.... none of those tags were found in the "normal" PNG file to begin with though, so at this stage I'm thinking that one or several of those tags the "normal" PNG already came with might be the one(s) responsible for turning on/off Preview's ability to display the EXIF date or not:

[ICC-view]      ViewingCondIlluminant     
[ICC-view]      ViewingCondSurround       
[ICC-view]      ViewingCondIlluminantType
[ICC-meas]      MeasurementObserver       
[ICC-meas]      MeasurementBacking       
[ICC-meas]      MeasurementGeometry       
[ICC-meas]      MeasurementFlare         
[ICC-meas]      MeasurementIlluminant     
[ICC-header]    ProfileCMMType           
[ICC-header]    ProfileVersion           
[ICC-header]    ProfileClass             
[ICC-header]    ColorSpaceData           
[ICC-header]    ProfileConnectionSpace   
[ICC-header]    ProfileDateTime           
[ICC-header]    ProfileFileSignature     
[ICC-header]    PrimaryPlatform           
[ICC-header]    CMMFlags                 
[ICC-header]    DeviceManufacturer       
[ICC-header]    DeviceModel               
[ICC-header]    DeviceAttributes         
[ICC-header]    RenderingIntent           
[ICC-header]    ConnectionSpaceIlluminant
[ICC-header]    ProfileCreator           
[ICC-header]    ProfileID                 
[ICC_Profile]   ProfileCopyright         
[ICC_Profile]   ProfileDescription       
[ICC_Profile]   MediaWhitePoint           
[ICC_Profile]   MediaBlackPoint           
[ICC_Profile]   RedMatrixColumn           
[ICC_Profile]   GreenMatrixColumn         
[ICC_Profile]   BlueMatrixColumn         
[ICC_Profile]   DeviceMfgDesc             
[ICC_Profile]   DeviceModelDesc           
[ICC_Profile]   ViewingCondDesc           
[ICC_Profile]   Luminance                 
[ICC_Profile]   Technology               
[ICC_Profile]   RedTRC                   
[ICC_Profile]   GreenTRC                 
[ICC_Profile]   BlueTRC                   
[ICC-view]      ViewingCondIlluminant     
[ICC-view]      ViewingCondSurround       
[ICC-view]      ViewingCondIlluminantType 
[ICC-meas]      MeasurementObserver       
[ICC-meas]      MeasurementBacking         
[ICC-meas]      MeasurementGeometry       
[ICC-meas]      MeasurementFlare           
[ICC-meas]      MeasurementIlluminant   
[PNG]           ProfileName   

.... I assume the only way to figure this out is to add each of these tags, one at a time, to the "stubborn" PNG and see which one enables Preview to display the EXIF date tag.


I'm having a little trouble figuring out the correct syntax of adding a tag though. Having read through several examples I found this to be the way to do it: $ exiftool "TAG_GROUP:TAGNAME:VALUE" FILENAME.PNG which appeared to work when adding for instance the XMP-x:XMPToolKit tag:
$ exiftool "-XMP-x:XMPToolKit=XMP Core 5.4.0" FILENAME.PNG

.. but adding PNG:ProfileName didn't work:

$ exiftool "-PNG:ProfileName=ICC Profile" FILENAME.PNG
Warning: Tag 'PNG:ProfileName' does not exist
Nothing to do


.... what is the correct syntax for adding tags as the above doesn't work (while clearly present in one of the files after analysing it with exiftool -a -G1 -s FILENAME.PNG)?

Phil Harvey

Quote from: pacman on March 19, 2016, 09:28:46 AM
Because I read

Quote
exiftool -r -overwrite_original_in_place '-datetimeoriginal&ltfilemodifydate' -if '(not $datetimeoriginal or ($datetimeoriginal eq "0000:00:00 00:00:00")) and ($filetype eq "TIFF")' .

Right.  This is because of the -if condition, just like I suggested earlier.

QuoteI'm having a little trouble figuring out the correct syntax of adding a tag though.

Adding a tag is just like writing a tag.  ExifTool will add it if it doesn't exist.

Quote.. but adding PNG:ProfileName didn't work:

Right.  See the PNG tags documentation for the reason.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

pacman

I see what you mean about the PNG tags (many which are not writeable with Exiftool).
Since I've tried to add just about all the other writeable tags to the file but still not getting Preview to display its time/date I can only assume that Lightroom adds some of the PNG tags which Exiftool can't write (but Lightroom can) that are essential to Preview.

Nevertheless, this is merely a frustration because it's just that I can't use Preview to quickly determine if a certain PNG file has its date or not embedded into the EXIF header. Perhaps I could create a drag & drop script for just that purpose using exiftool -a -G1 -s FILENAME.PNG (or look into another exiftool command which will just display the EXIF time/date if available, or alert that it's not there).
And when I'm done adding time/date to all the files' EXIF headers I'll be saving the metadata to the files in Lightroom anyway which will in turn let the time/date show when viewed in Preview, so it's really just an intermediate problem/frustration  ;)

So what's left of the whole Lightroom puzzle now is to figure out a way to use Exiftool together with another command-line tool allowing the correct file date to be rewritten... Failing that there's always A Better Finder Attributes.