Add "mac created date" into .jpg exif

Started by arnaudarthur, December 23, 2015, 03:58:49 AM

Previous topic - Next topic

arnaudarthur

Hi Phil, hi everyone,
First congrats for this tools Phil, it look really powerful, even if I have a bit of a hard time handle it.
But i try my best, and after few search on this forum, succeed in first exercice ;)

Quickly, here is my issue :
I processed around 4000 jpeg into ImageOptim, a superb image optimizer. But unfortunalty I lost my exif data.
Hopefully, my mac keep a "created date" " ? " as you can see on this screenshot: 
https://www.dropbox.com/s/ronqggtlhe2to5o/screenshotExif.jpg

When I open this image in an Exif editor, it just say something like "no exif detail"

As you can imagine, my goal is to add this data "created date" display on mac OS into the Exif.
( with this my picture will be organized again on flickr / google photos / dropbox / etc. )

If we can find a good terminal lines for completed this goal, I will convert it into a droplet / automator.
Like this lazy mac user like me will avoid headache ;)

thanks, I hope my issue sounds clear.

arnaudarthur

I try to play a bit around with this thread :
https://exiftool.org/forum/index.php/topic,6839.msg34246.html#msg34246

And this is the reply of the terminal...
It looks like it doesn't access to the "created date" here neither.
https://www.dropbox.com/s/j7fjadsjqbxuimz/Screenshot%202015-12-23%2010.50.31.png?dl=0

I feel there is something easy I can do. But I can't find it yet :'D

Phil Harvey

Unfortunately ExifTool doesn't have access to the Mac file creation date/time.  If the file modification date/time is set, then you may use this (the ExifTool FileModifyDate tag), but otherwise I'm afraid you are out of luck with ExifTool.

There may be a utility that lets you set the file modification date/time from the file creation date, but I couldn't find it with a quick Google.

- 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 ($).

Phil Harvey

A bit more googling and I found a way to do this one file at a time:

exiftool FILE -P -createdate="`mdls -name kMDItemFSCreationDate -raw FILE`"

This will set the EXIF CreateDate of FILE to the OS X file creation date/time.

- 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 ($).

PAPPL

#4
Hi,
i'm no expert, but afaik you need -exif:datetimeoriginal (=Exif Photo Taken) or -alldates (=DateTimeOriginal, CreateDate and ModifyDate) command to write dates to EXIF-Information.
See FAQ #5: http://www.exiftool.org/faq.html

exiftool '-alldates<filemodifydate' -P  -overwrite_original_in_place -if '(not $dateTimeOriginal)' filename.jpg or -r DIR

UPDATE: Doesn't work with filecreatedate, not write/readable! See Phils solution!

But be aware: when you write a file the date/time gets reset to today's date! The -P -overwrite_original_in_place command should avoid this. So try with one copy of your jpg first!

Added-if '(not $dateTimeOriginal)' in front of filename.jpg or -r DIR to only write exif-information to files which do not contain exif creation date information. This will avoid overwriting files with exif accidentally. Remove if unwanted.



See FAQ #24 for more information regarding OSX options.

Phil Harvey

I've been playing with this, and have found an OS X "mdls" command that lists all OS X metadata.  I will add support for this to the next version, so that a command something like this will do what you want with ExifTool 10.09:

exiftool "-createdate<MDItemFSCreationDate" -r DIR

- 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 ($).

Hayo Baan

Very nice Phil, I should have thought about mdls myself, but for the create time I had already found another source: the stat command. It has a forth time parameter that can be retrieved, the birth time. Eg., stat -f '%SB' FILE which will display the file creation time in readable form. See the command line manual for more formatting options.
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

Thanks for the tip.  I didn't know that stat could return the creation time.

- 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 ($).

arnaudarthur

Thanks for your help everyone,
@Phil first solution works, but as we know it's not applicable for a batch of 3000 images.
Sounds like I should way for this new update including a new command ;)
@Hayo Baan, I understrand your thought but I'm not good enough to apply it " I think".
It's two step process right? I've read the manual but haven't found it yet...



Hayo Baan

Quote from: arnaudarthur on December 25, 2015, 11:55:04 AM
@Hayo Baan, I understrand your thought but I'm not good enough to apply it " I think".
It's two step process right? I've read the manual but haven't found it yet...

To apply the birth date from the stat command as I said, would indeed be a two step thing (though you might be able to combine it with e.g., the backtick operator if you're on Mac/UNIX, but that's pretty advanced). I'd wait for Phil to integrate this into exiftool though as that will make your life much easier  :)
Hayo Baan – Photography
Web: www.hayobaan.nl

arnaudarthur

btw @Phil,
the function is doing the process in reverse. It's replacing the finder "created date" by the EXIF :
exiftool FILE -P -createdate="`mdls -name kMDItemFSCreationDate -raw FILE`"
https://www.dropbox.com/s/d670z0d779rtu2d/PhilFunction.jpg?dl=0

Any way to reverse it ?

Or perhaps another solution will be to replace the modified date with the created date?
My only need is that google photos can display them chronologically ;)

Ah when I start looking around few days ago, this sounded like something super easy ahah, such a good learning for the christmas time :D

Have a nice day everyone

Phil Harvey

Right.  You probably want to preserve the original file creation date/time when writing.  To do this, and also preserve the filemodifydate, add -overwrite_original_in_place -P to the 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 ($).

Phil Harvey

I've just released ExifTool 10.09 with the ability to read the OS X system metadata.  Here is an example output from a JPEG image with no embedded metadata:

> exiftool -a -G1 -s -api MDItemTags a.jpg
[ExifTool]      ExifToolVersion                 : 10.09
[System]        FileName                        : a.jpg
[System]        Directory                       : .
[System]        FileSize                        : 251 bytes
[System]        FileModifyDate                  : 2016:01:04 11:11:08-05:00
[System]        FileAccessDate                  : 2016:01:04 11:20:51-05:00
[System]        FileInodeChangeDate             : 2016:01:04 11:11:08-05:00
[System]        FilePermissions                 : rw-r--r--
[System]        MDItemBitsPerSample             : 32
[System]        MDItemColorSpace                : RGB
[System]        MDItemContentCreationDate       : 2016:01:04 16:11:08+0000
[System]        MDItemContentModificationDate   : 2016:01:04 16:11:08+0000
[System]        MDItemContentType               : public.jpeg
[System]        MDItemContentTypeTree           : public.jpeg, public.image, public.data, public.item, public.content
[System]        MDItemDateAdded                 : 2016:01:04 16:11:08+0000
[System]        MDItemDisplayName               : a.jpg
[System]        MDItemFSContentChangeDate       : 2016:01:04 16:11:08+0000
[System]        MDItemFSCreationDate            : 2016:01:04 16:11:08+0000
[System]        MDItemFSCreatorCode             :
[System]        MDItemFSFinderFlags             : 0
[System]        MDItemFSHasCustomIcon           :
[System]        MDItemFSInvisible               : 0
[System]        MDItemFSIsExtensionHidden       : 0
[System]        MDItemFSIsStationery            :
[System]        MDItemFSLabel                   : 0
[System]        MDItemFSName                    : a.jpg
[System]        MDItemFSNodeCount               :
[System]        MDItemFSOwnerGroupID            : 20
[System]        MDItemFSOwnerUserID             : 501
[System]        MDItemFSSize                    : 251
[System]        MDItemFSTypeCode                :
[System]        MDItemHasAlphaChannel           : 0
[System]        MDItemKind                      : JPEG image
[System]        MDItemLogicalSize               : 251
[System]        MDItemOrientation               : 0
[System]        MDItemPhysicalSize              : 4096
[System]        MDItemPixelCount                : 64
[System]        MDItemPixelHeight               : 8
[System]        MDItemPixelWidth                : 8
[System]        MDItemResolutionHeightDPI       : 0
[System]        MDItemResolutionWidthDPI        : 0
[File]          FileType                        : JPEG
[File]          FileTypeExtension               : jpg
[File]          MIMEType                        : image/jpeg
[File]          ImageWidth                      : 8
[File]          ImageHeight                     : 8
[File]          EncodingProcess                 : Baseline DCT, Huffman coding
[File]          BitsPerSample                   : 8
[File]          ColorComponents                 : 3
[File]          YCbCrSubSampling                : YCbCr4:2:0 (2 2)
[Composite]     ImageSize                       : 8x8
[Composite]     Megapixels                      : 0.000064


In my timing tests (on a 2.7 HGz Intel Core i5 iMac), using the MDItemTags API option incurs a penalty of about 37 ms per file, which is not insignificant.  In this version of ExifTool, the 37 ms overhead is always incurred when copying tags (since RequestAll is automatically set when copying), but 10.10 will allow you to prevent this by setting MDItemTags to 0.

- 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 ($).