ExifTool Forum

ExifTool => The Image::ExifTool API => Topic started by: mrbrahman on May 27, 2018, 10:36:35 AM

Title: More than one Date Format
Post by: mrbrahman on May 27, 2018, 10:36:35 AM
Hi,

Is there someway to specify more than one date format?

For e.g. obtain CreateDate and DateTimeOriginal in one format (YYYY-MM-DD HH:MI:SS), and FileModifyDate in Epoch.

Thank you
Title: Re: More than one Date Format
Post by: Phil Harvey on May 27, 2018, 02:01:36 PM
You could have to do something fancy to get a date in the epoch, but this could be done by overriding the Extra:FileModifyDate to disable all conversions with a config file like this:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Extra' => {
        FileModifyDate => { },
    },
);
1;  #end


Then the -d option could be used to format the other date/time tags.

- Phil

Title: Re: More than one Date Format
Post by: mrbrahman on May 27, 2018, 04:16:28 PM
Thanks for looking into this. I should have posted my code first.


$ cat t.pl
use Image::ExifTool qw(:Public);

my $filename = "/home/mrbrahman/Pictures/2018/2018-04-04 Some Event/IMG_20180404_203006.jpg";
my @tags = qw( DateTimeOriginal# CreateDate# FileModifyDate);
my %options = (DateFormat => '%s'); #'%Y-%m-%d %H:%M:%S'

my $info = ImageInfo($filename, \@tags, \%options);

map { print $_." :".$info->{$_}."\n" } keys(%{$info});

$
$ perl t.pl
DateTimeOriginal # :2018:04:04 20:30:06
CreateDate # :2018:04:04 20:30:06
FileModifyDate :1526480310


The FileModifyDate is indeed coming out as Unix Epoch, but the other formats are the POSIX format.

I'd like the other 2 fields to come out in YYYY-MM-DD HH:MI:SS format.

Is that possible?

Thanks.
Title: Re: More than one Date Format
Post by: Phil Harvey on May 28, 2018, 07:31:00 AM
You have disabled the date formatting with the trailing "#" on the tag names.

- Phil
Title: Re: More than one Date Format
Post by: mrbrahman on May 28, 2018, 09:54:22 AM
So, here's the output with the # removed and the format is unix epoch on all 3.


$ cat t.pl
use Image::ExifTool qw(:Public);

my $filename = "/home/mrbrahman/Pictures/2018/2018-04-04 Some Event/IMG_20180404_203006.jpg";
my @tags = qw( DateTimeOriginal CreateDate FileModifyDate);
my %options = (DateFormat => '%s'); #'%Y-%m-%d %H:%M:%S'

my $info = ImageInfo($filename, \@tags, \%options);

map { print $_.": ".$info->{$_}."\n" } keys(%{$info});


$ perl t.pl
CreateDate: 1522888206
DateTimeOriginal: 1522888206
FileModifyDate: 1526480310


Is it possible to get the YYYY-MM-DD HH:MI:SS format for only the CreateDate and DateTimeOriginal fields?

Thanks

Title: Re: More than one Date Format
Post by: Phil Harvey on May 28, 2018, 10:03:07 AM
You can do it with a user-defined tag as I mentioned:

$ cat t.pl
use Image::ExifTool qw(:Public);

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Extra' => {
        FileModifyDate => { },
    },
);

my $filename = "a.jpg";
my @tags = qw( DateTimeOriginal CreateDate FileModifyDate);
my %options = (DateFormat => '%Y-%m-%d %H:%M:%S');

my $info = ImageInfo($filename, \@tags, \%options);

map { print $_.": ".$info->{$_}."\n" } keys(%{$info});


- Phil
Title: Re: More than one Date Format
Post by: mrbrahman on May 28, 2018, 08:12:01 PM
Thanks so much!
Title: Re: More than one Date Format
Post by: mrbrahman on June 02, 2018, 12:39:01 PM
I tried to implement the same for 2 other fields -- FileSize and Orientation.

FileSize is giving me the proper value (in bytes), bur Orientation is not.



$ cat t.pl
use File::Find::Iterator;
use Image::ExifTool qw(:Public);
use Data::Dumper;

sub isfile { -f }

my $find = File::Find::Iterator->create(dir => ["images/"], filter => \&isfile)
              or die "ERROR: Cannot read Directory";

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Extra' => {
        FileModifyDate => { },
        FileSize => { },
        Orientation => { },
    },
);

my %options = (DateFormat => '%Y-%m-%d %H:%M:%S');
my @tags = qw( FileName FileSize Orientation MIMEType Keywords RegionName Rating Make DateTimeOriginal CreateDate FileModifyDate);

while (my $filename = $find->next) {
  my $info = ImageInfo($filename, @tags, \%options);
  print Dumper($info);
}



$ perl t.pl
$VAR1 = {
          'CreateDate' => '2017-12-25 20:06:31',
          'FileSize' => 2392267,
          'MIMEType' => 'image/jpeg',
          'Rating' => '5',
          'FileModifyDate' => 1527631893,
          'DateTimeOriginal' => '2017-12-25 20:06:31',
          'RegionName' => 'Brahman',
          'Make' => 'LGE',
          'Keywords' => 'Cousins',
          'FileName' => 'IMG_20171225_200630.jpg',
          'Orientation' => 'Horizontal (normal)'
        };


Anything special needed here?

Thanks!
Title: Re: More than one Date Format
Post by: Phil Harvey on June 03, 2018, 08:09:14 AM
FileSize is an Extra tag (https://exiftool.org/TagNames/Extra.html), so this works, but Orientation is an EXIF Tag (https://exiftool.org/TagNames/EXIF.html), so you must override this in the EXIF table.

But I don't think this should be necessary.  Just request Orientation# instead of Orientation.  Same with FileSize actually.  The reason you needed to override FileModifyDate is because the unformatted value was a string format, and you wanted the unix epoch.  But for both FileSize and Orientation the unformatted value is an integer.

- Phil
Title: Re: More than one Date Format
Post by: mrbrahman on June 06, 2018, 04:05:34 PM
Thank you Phil!