ExifTool Forum

ExifTool => Archives => Topic started by: Archive on May 12, 2010, 08:54:00 AM

Title: GPSDateStamp and GPSTimeStamp insert problem
Post by: Archive on May 12, 2010, 08:54:00 AM
[Originally posted by bsmithy on 2007-02-13 20:28:48-08]

Hi,

 I'm trying to 'copy' the DateTimeDigitized from the image file into the both the GPSDateStamp and GPSTimeStamp tags, but am having problems. I'm getting errors on both. In the case of GPSTimeStamp: Not enough values specified (3 required); and for GPSDateStamp: String too long.

 I've set up two User defined tags to parse the DateTimeDigitized tag, thinking that might fix it, but no luck. So my question is, how do I copy the DateTimeStamp to the two other tags?

 My user defined tag (the other one is similar):
Code:
  GPSTimeValue => {
     0 => 'DateTimeDigitized',
   },
   PrintConv => 'subst($val[0],index($val[0]," ")+1,index($val[0],"-")-index($val[0]," ")-1)',
 },

 -Bill
Title: Re: GPSDateStamp and GPSTimeStamp insert problem
Post by: Archive on May 12, 2010, 08:54:00 AM
[Originally posted by exiftool on 2007-02-13 23:00:44-08]

Hi Bill,

Did you look at the example tags in the sample ExifTool_config?
You need to define these as Composite tags, which take a "Require"
hash to define the tags it is based upon.  Also, the ValueConv
must be defined for a Composite tag.

And are you sure you want to use DateTimeDigitized?  CreateDate
would be a more obvious choice.  Anyway, here is an example of
how this could be done. (disclaimer: I haven't tested this code)

 
Code:
'Image::ExifTool::Composite' => {
     GPSTimeValue => {
         Require => {
             0 => 'DateTimeDigitized',
         },
         ValueConv => '$val[0] =~ / (.*)/; $1',
     },
     GPSDateValue => {
         Require => {
             0 => 'DateTimeDigitized',
         },
         ValueConv => '$val =~ /(.*) /; $1',
     },
 },

- Phil
Title: Re: GPSDateStamp and GPSTimeStamp insert problem
Post by: Archive on May 12, 2010, 08:54:00 AM
[Originally posted by bsmithy on 2007-02-14 00:28:13-08]

Hi Phil,

 Thanks for the quick response!

 I had defined the tags as Composite and defined the required base tag, sorry - I forgot to include that when I pasted the code in the original post. I based my composite tag(s) on the ones in ExifTool_config and had, at first tried the ValueConv definition, but I was getting the same result as using the PrintConv. I was getting the right values in the Composite tag(s), but I couldn't assign them to the GPSDateStamp/GPSTimeStamp tags from the command line using '-GPSDateStamp=$GPSDateValue'. I see how your snippet is different in the assignment to val[], where I wasn't doing that. Guess I need to brush up on my Perl!

 Thanks again.

-Bill
Title: Re: GPSDateStamp and GPSTimeStamp insert problem
Post by: Archive on May 12, 2010, 08:54:00 AM
[Originally posted by exiftool on 2007-02-14 00:42:10-08]

Hi Bill,

Great, glad that worked.

Just to explain what the "$val[0] =~ /regex/" does:

It isn't an assignment.  The "=~" operator parses $val[0]
with the specified regular expression.  Then the ValueConv
returns "$1", which is the string that matches the pattern
inside the brackets of the regular expression.  There are
many different ways to accomplish this without regular
expressions as you were doing, but if you know Perl, regular
expressions frequently produce the most compact code.

- Phil
Title: Re: GPSDateStamp and GPSTimeStamp insert problem
Post by: Archive on May 12, 2010, 08:54:01 AM
[Originally posted by bsmithy on 2007-02-15 00:44:29-08]

Phil,

 I spoke to soon. I'm still not having any luck assigning the generated tag value to GPSTimeStamp or GPSDateStamp tags. I'm still getting the same error(s). What I'm trying to do is assign the value from the command line, like: exiftool -GPSDateStamp=$GPSDateValue image.jpg. When I do this, I get the following errors and no assignment:

With GPSTimeStamp: Not enough values specified (3 required) for GPS:GPSTimeStamp

With GPSDateStamp: String too long for GPS:GPSDateStamp

Nothing to do

So, I guess I'm still stuck. The custom tags do show with exiftool -g1 image.jpg in the Custom group with the right values. The problem seems to lie in the assignment of the custom value to the GPS: tag(s).

- Bill
Title: Re: GPSDateStamp and GPSTimeStamp insert problem
Post by: Archive on May 12, 2010, 08:54:01 AM
[Originally posted by exiftool on 2007-02-15 13:26:28-08]

Hi Bill,

I think your problem is a command-line issue.  The equal sign is used for assigning values to a tag, but what you want to do is copy the value of another tag.  To do this, use "<" instead of "=".  Here is the command-line you want:

Code:
exiftool "-gpstimestamp<gpstimevalue" "-gpsdatestamp<gpsdatevalue" image.jpg

You could use an expression as you did (ie. "-gpstimestamp<$gpstimevalue"), but this is not necessary in this simple case.

Also, I had time to test this out, and I made a mistake in my ValueConv for GPSDateValue (I forgot the subscript on $val[0]).  So here is the full .ExifTool_config file that should work for you (note I have changed DateTimeDigitized to the more commonly available CreateDate

Code:
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        GPSTimeValue => {
            Require => {
                 0 => 'CreateDate',
            },
            ValueConv => '$val[0] =~ / (.*)/; $1',
        },
        GPSDateValue => {
            Require => {
                0 => 'CreateDate',
            },
            ValueConv => '$val[0] =~ /(.*) /; $1',
        },
    },
);

- Phil
Title: Re: GPSDateStamp and GPSTimeStamp insert problem
Post by: Archive on May 12, 2010, 08:54:01 AM
[Originally posted by bsmithy on 2007-02-15 13:34:43-08]

Phil,

 Thanks again for the quick reply.

 I 'fixed' your example from the prior response, so no problem there. I now understand the difference between the 'copy' and 'assign' on the command-line. It was confusing me a bit as I could do "-gsptimestamp=1:0:0" and it would work, my custom tags where being created correctly, but not being assigned when I did '-gpstimestamp=$gpstimevalue'. With the 'copy tag' instead of the 'assing value' on the command-line it now does work correctly!

Thanks again for both your help and ExifTool!

-Bill
Title: Re: GPSDateStamp and GPSTimeStamp insert problem
Post by: Archive on May 12, 2010, 08:54:01 AM
[Originally posted by bsmithy on 2007-02-15 13:48:27-08]

Phil,

 Thanks again for the quick reply.

 I 'fixed' your example from the prior response, so no problem there. I now understand the difference between the 'copy' and 'assign' on the command-line. It was confusing me a bit as I could do "-gsptimestamp=1:0:0" and it would work, my custom tags where being created correctly, but not being assigned when I did '-gpstimestamp=$gpstimevalue'. With the 'copy tag' instead of the 'assing value' on the command-line it now does work correctly!

Thanks again for both your help and ExifTool!

-Bill