Set IPTC date/time from EXIF

Started by sjs, June 06, 2010, 10:08:25 AM

Previous topic - Next topic

sjs

Hi everybody!

I'm very new to exiftool (absolutely great piece of software! :) ) and am surprised that the following question isn't a FAQ... :)

Is there a way to set the IPTC "Date Created" and "Time Created" fields based on the EXIF "Date taken" information? Preferably by a "one liner"...
This should also take into account the EXIF timezone information and write a "full" IPTC/IIM time header according to the scheme "HHMMSS±HHMM". (With "±HHMM" being the timezone offset in hours in minutes relative to UTC.)


Thanks,

Sebastian

Phil Harvey

Hi Sebastian,

Unfortunately there is no timezone specification in the EXIF.  To set the IPTC:Date/TimeCreated from the EXIF information, you do this:

exiftool "-iptc:datecreated<createdate" "-iptc:timecreated<createdate" FILE

The timezone will be taken from the current system timezone.  If you want to specify another timezone (say +05:00), you can do this:

exiftool "-iptc:datecreated<createdate" "-iptc:timecreated<${createdate}+05:00" FILE

(if you are on Mac or Linux be sure to use single quotes for the argument containing a "$" symbol instead of double quotes as above)

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

sjs

Quote from: Phil Harvey on June 06, 2010, 02:17:38 PM
Unfortunately there is no timezone specification in the EXIF.

Well, you're right that it's not specified officially, but an "unofficial" EXIF header field seems to exist anyway - you write that yourself in http://www.exiftool.org/TagNames/EXIF.html (0x882a, TimeZoneOffset).  ;D
Let's assume for a second that this header is already set correctly - do you have a suggestion how to use in the sense of my original question?

But aside from that: Thanks for the "code" you already gave me. This looks actually quite simple. :)

Quote from: Phil Harvey on June 06, 2010, 02:17:38 PM
The timezone will be taken from the current system timezone.

What does that mean exactly? Does this mean that the UTC offset I have right now is used? Or does it mean that the actual UTC offset at the given EXIF date, based on my local timezone setting is used?
I'm thinking of daylight saving time here...
In other words: My current timezone is UTC+2h. For an image taken in December it would be UTC+1h - what will be written into the IPTC field in case I use your command on a December image file now?


Regards,

Sebastian

Phil Harvey

Quote from: sjs on June 06, 2010, 03:32:32 PM
(0x882a, TimeZoneOffset).  ;D
Let's assume for a second that this header is already set correctly - do you have a suggestion how to use in the sense of my original question?

This is a bit tricky since the TimeZoneOffset tag may have 1 or 2 values (and neither applies to the CreateDate, but I'll ignore this problem for now).

The difficulty is that TimeZoneOffset isn't formatted such that it can directly be used as a time zone.  With this config file I define a new tag called MyTimeZone which reformats the TimeZoneOffset as required:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyTimeZone => {
            Require => 'TimeZoneOffset',
            ValueConv => '$val=~s/\s.*//; sprintf("%+.2d:00",$val)',
        },
    },
);
1;  #end


which allows me to do this:

exiftool "-iptc:datecreated<createdate" "-iptc:timecreated<${createdate}${mytimezone}" FILE

QuoteWhat does that mean exactly? Does this mean that the UTC offset I have right now is used? Or does it mean that the actual UTC offset at the given EXIF date, based on my local timezone setting is used?
I'm thinking of daylight saving time here...

This is an excellent point.  Unfortunately since the corresponding time tag is written separately in IPTC, the date is not known when I determine the local time zone.  So the current local time difference from UTC is used, which as you point out may easily be wrong if you write a corresponding date which has a different DST.  This is a problem for which I haven't figure out a reasonable solution.

- 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 just realized that in the case where an IPTC time is set from a date/time value (as you are doing), then I do have enough information to determine the local timezone offset.  I will implement this in the next release.

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