Page 1 of 1

String manipulation methods for EXIF tags

Posted: 2008-05-08T14:52:02-07:00
by gadni
Hello!

I have a question/request regarding the usage of special EXIF tags in -caption -annotate -format etc. commands.
Is it possible to embed, for example, just the date part of the "%[EXIF:DateTime]" tag or to display it in a custom
format (eg. "dd.mm.yyyy")?

In addition, if we define the problem universally, is there any way to apply manipulation functions upon the strings -
for example, mid, pos, left, right...

Thanks in advance!
I am very impressed of the possibilities of your software and thank you so much for this jewel!

Ivaylo Ivanov

Re: String manipulation methods for EXIF tags

Posted: 2008-06-05T18:42:53-07:00
by anthony
No. IM has no string manipulation constructs. that is getting sub-strings from larger stings.

At least not yet, and probably not any time soon.
You will be better of using the wrapping API to do that type of work.

Re: String manipulation methods for EXIF tags

Posted: 2008-06-08T06:42:26-07:00
by gadni
Thanks,

And how about something like: "%[EXIF:DateTime:dd.mm.yyyy]" which is just for the EXIF tags, not for ANY string constant, if it's so difficult?

Cheers!

anthony wrote:No. IM has no string manipulation constructs. that is getting sub-strings from larger stings.

At least not yet, and probably not any time soon.
You will be better of using the wrapping API to do that type of work.

Re: String manipulation methods for EXIF tags

Posted: 2008-06-08T15:20:02-07:00
by fmw42
And how about something like: "%[EXIF:DateTime:dd.mm.yyyy]" which is just for the EXIF tags, not for ANY string constant, if it's so difficult?
I have never used them, but there are DateTime tags for EXIF. See http://www.imagemagick.org/script/escape.php

Re: String manipulation methods for EXIF tags

Posted: 2008-06-09T17:32:22-07:00
by anthony
The problem is then IM has to be able to parse a date/time string so that it can reformat it to what you request. that is not simple especially as many programs like jhead lets you put just about anything into that string field!!!! It is very free form.

jhead does has parsers for this tag and is better suited to this task as it will extract it without reading in the image data. IM is a image processor, not a EXIF processor!

Re: String manipulation methods for EXIF tags

Posted: 2008-06-10T05:16:28-07:00
by gadni
My question was raised because in my region (Greetings from Bulgaria :-) )
we use dates in format "dd.mm.yyyy" (German like) which is not what this EXIF tag is returning.
No matter of this limitation, I am still so happy with ImageMagick :-)

Thank you, Anthony and congrats for your brilliant work!

Re: String manipulation methods for EXIF tags

Posted: 2008-06-11T22:15:45-07:00
by anthony
I know the feeling we in Australia use a similar style.

The best solution is to use Jhead to modify all the date strings in the image EXIF tags. It does this without decoding the JPEG image data so their is no loss of quality.

Re: String manipulation methods for EXIF tags

Posted: 2008-06-15T02:20:31-07:00
by gadni
Which one of the jHead options is for midifying DateTime exif tag in the JPG with specifying new format?
I haven't noticed option for writing into JPG a value with custom format.

And something more: jHead operates (lists and modifies) DateTime tag. I need to modify DateTimeOriginal tag,
because it's value is preserved exactly as it was by the time photo was taken. DateTime tag value is modified
by many photo editing programs and doesn't give meaningful info for the photo origin.

Cheers!

Re: String manipulation methods for EXIF tags

Posted: 2008-06-15T17:07:01-07:00
by anthony
Hmmm... I may be wrong. The date may be stored as some type of number n the EXIF header. which means how the number is to be displayed is up to the program making use of that number.

It may be that IM will need some type of global 'date-format' setting to redefine how dates from the EXIF (as well as file creation and modified dates) should be formated. Or better still IM should get that information from the Internationalization/Locale (I18n) settings of the system on which it is running.

On my linux system the date format was defined in the appropriate /usr/share/i18n/locales/ file. "en_AU" in my case.

Maybe if you define your LC_TIME environment variable it will actually distplay right in both IM and jhead!!!

I am just not sure, try it and report back.

Re: String manipulation methods for EXIF tags

Posted: 2008-06-15T17:43:34-07:00
by magick
EXIF dates are stored as strings, for example, '2006:10:23 11:04:40'. If it was stored as integer values we would have an opportunity to format the date but as strings we just copy them intact. The EXIF specification says:
The date and time when the original image data was generated. For a DSC the date and time the picture was taken
are recorded. The format is "YYYY:MM:DD HH:MM:SS" with time shown in 24-hour format, and the date and time
separated by one blank character [20.H]. When the date and time are unknown, all the character spaces except
colons (":") may be filled with blank characters, or else the Interoperability field may be filled with blank characters.
The character string length is 20 bytes including NULL for termination. When the field is left blank, it is treated as
unknown.

Re: String manipulation methods for EXIF tags

Posted: 2008-06-15T18:11:02-07:00
by anthony
Well that makes this very clear.

If you want to label images using your own date format, you will need to extract that date in the API you are using (be it shell, PHP, or some other language), modify it and then make use of it as you like.

Sorry...

Re: String manipulation methods for EXIF tags

Posted: 2008-06-21T12:22:52-07:00
by gadni
Yep, that's a pity...I'll use an external identification program.

Thanks, guys!
All the best!

Re: String manipulation methods for EXIF tags

Posted: 2008-06-21T14:46:06-07:00
by Bonzo
You can modify the date with php( PHP 5 >= 5.1.0) ; as well as displaying the date you could use the variable in the IM code ??
I have not had time to see how this code works fully.

Code: Select all

<?php
exec("identify -format \"%[EXIF:DateTime]\" image.jpg", $a);

// http://www.tutorialspoint.com/php/php_function_date_format.htm
$dateSrc = $a[0];
   $dateTime = date_create( $dateSrc);
   # Now set a new date using date_format();
   date_format( $dateTime, 2000, 12, 12);
   echo "New Formatted date is ". $dateTime->format("d-m-Y");
   echo "<br />";
?>