Adding additional unknown tags to existing images

Started by Archive, May 12, 2010, 08:53:56 AM

Previous topic - Next topic

Archive

[Originally posted by rshbkr on 2006-09-06 21:53:14-07]

Hi,
 I need to add additional tags to existing tiff images, with specific values associated with each image. Did not use ExifToll till now. Want to use ExifToll as a module instead of the command line option.
 how can i add the tags and values to existing tiff images.(The TAG #'s are in the range of 45000 to 45016)

Thanks
Raja

Archive

[Originally posted by exiftool on 2006-09-07 00:05:10-07]

Hi Raja, I've got some reading for you:

First, you should look through the API documentation by typing "perldoc Image::ExifTool" or browsing
html/ExifTool.html.  This gives you details about how to call the functions in the module.  This part
should be relatively straightforward once you have a feel for the API.  Basically, all you need to do is
something like this:

Code:
my $exifTool = new Image::ExifTool;
$exifTool->SetNewValue('MyNewTag' => $value);
$exifTool->WriteInfo($file);

Then you should look at "ExifTool_config" for example of how to add user-defined tags.  There isn't an
example for adding an EXIF tag, but you can do it with an entry like this to your "~/.ExifTool_config"
file:

Code:
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Exif::Main' => {
        45000 => {
            Name => 'MyNewTag',
            Writable => 'int16u',
            WriteGroup => 'IFD0',
        },
    },
);

The tag is written to the ExifIFD by default unless you specify another WriteGroup as IFD0 above.  The Writable attribute
must be set according to the format for the value.  You can also add value conversions (ValueConv, ValueConvInv) and
print conversions (PrintConv, PrintConvInv) if necessary.

Finally, you can read lib/Image/ExifTool/README for details about these attributes if necessary.  Also see Exif.pm and
WriteExif.pl for examples of attributes used for other tags.

Archive

[Originally posted by rshbkr on 2006-09-07 17:55:25-07]

Thanks for the help.
I was able to add new userdefined tags and it worked.

Archive

[Originally posted by panday on 2006-10-02 18:49:14-07]

Hi!

Newbee here.

I've recently tried exploring ExiifTool to embed XMP information in my images (Note: It's also only recently that I started learning Perl).

Anyway, I've tried the following code:

Code:
   #!/usr/bin/perl</i>

    use Image::ExifTool;

       $exifTool->SetNewValue('tag1','data1');
       $exifTool->WriteInfo('test.tif');

However, I keep on getting this error message --
Can't call method "SetNewValue" on an undefined value at test.pl line 5.

Any idea on where I went wrong??

Any replies will be greatly appreciated and thank you in advance.

- Panday

Archive

[Originally posted by exiftool on 2006-10-02 19:17:25-07]

Hi Panday,

You've forgotten the following line from my example:

Code:
my $exifTool = new Image::ExifTool;

You need to create an ExifTool object to use for accessing the writer functions.

Also, for your code to work, 'tag1' will need to be a valid tag name.

- Phil

Archive

[Originally posted by panday on 2006-10-02 21:25:25-07]

Thanks Phil! I think that resolve my earlier problem. However, you mentioned that my code would only work for a valid tag. I've tried making some edits to the ExifTool_config file as well as the XMP.pm file however I'm still getting an error message:

Code:
Tag 'tag1' does not exist
I want to add custom tailored metadata information such as <xap:volume>, <xap:issue> and <xap:publication>. I hope I'm not asking to much questions and again thank you in advance.

- Panday

Archive

[Originally posted by panday on 2006-10-02 21:45:00-07]

Here's some of the lines I added to the ExifTool_config

Code:
%Image::ExifTool::UserDefined::xap = (
    GROUPS => { 0 => 'XMP', 1 => 'XMP-xap', 2 => 'Image' },
    NAMESPACE => [ 'xap' => 'http://ns.myname.com/xap/1.0/' ],
    WRITABLE => 'string',
    volume => { },
);

and

Code:
'Image::ExifTool::XMP::Main' => {
        xap => {
            SubDirectory => {
                TagTable => 'Image::ExifTool::UserDefined::xap',
            },
        },
    },
    'Image::ExifTool::XMP::xap' => {
        volume => { } },
    },

Archive

[Originally posted by exiftool on 2006-10-02 22:42:00-07]

There are a few problems with this:

1) I think you probably have too many right braces on the line with "volume => {}},".

2) Your "xap" namespace conflicts with an existing namespace.  "xap" is the old name used for the
"xmp" namespace.  So you will have to choose another namespace prefix.

3) The table "Image::ExifTool::XMP::xap" doesn't exist. So your last definition will result in an
error.

4) You have attempted to define the "volume" tag twice.  Deleting all of the following code will
solve problems 1, 3 and 4:

Code:
'Image::ExifTool::XMP::xap' => {
        volume => { } },
    },

But in the process, you've highlighted a problem in ExifTool:  I should be printing warning messages
if there are syntax errors in the config file.  This will be fixed in the next version, and I have uploaded
a pre-release here
since it may be useful to you.

- Phil

Archive

[Originally posted by panday on 2006-10-03 01:18:14-07]

Again Phil thank you for being patient with me.

I'm also glad that I was able to help report a minor bug

It was my intention to use "xap" - the old name space of "xmp". If I could simplify my earlier question, what if I want to add a new tag in the current "xap" namespace?

Just to further illustrate what I have in mind, here's an example of the XMP I need to embed inside the image

Code:
 <rdf:Description>
       <xap:Volume>8</xap:Volume>
       <xap:Number>2</xap:Number>
       <xap:Publication>Liwayway</xap:Publication>
       <xap:PubDate>
            <rdf:Alt>
                  <rdf:li>09/12/2006</rdf:li>
            </rdf:Alt>
       </xap:PubDate>
       <xap:Subject>
            <rdf:Bag>
                  <rdf:li>Horror</rdf:li>
            </rdf:Bag>
       </xap:Subject>
 </rdf:Description>
Again, thank you.

- Henry Santyana

Archive

[Originally posted by exiftool on 2006-10-03 02:02:46-07]

Adding to an existing namespace is easier. The only trick here is that you have
to use the newer 'xmp' namespace, not the older 'xap'.  (Although ExifTool will honour
the older namespaces if they already exist in the information.)

So all you needed was the part I told you to delete before (in the
%Image::ExifTool::UserDefined hash), just like the 'NewXMPxmpTag' example:

Code:
   'Image::ExifTool::XMP::xmp' => {
        Volume => { },
    },

(Note the capitalized 'Volume', if that is how you want it recorded in the XMP.)

- Phil

Archive

[Originally posted by panday on 2006-10-03 04:00:56-07]

Hello Phil!

I'm still getting an error.

Code:
Tag 'Volume' does not exist
What I did was add

Code:
Volume => { },
where the

Code:
NewXMPxmpTag => { Groups => { 2 => 'Author' } },
used to be placed.

As for my code:

Code:
#!/usr/bin/perl

use Image::ExifTool;

  my $exifTool = new Image::ExifTool;
  $exifTool->SetNewValue('Volume','01');
  $exifTool->WriteInfo('test.tif');
Am I still missing anything?

- Henry Santyana

Archive

[Originally posted by exiftool on 2006-10-03 13:08:30-07]

Hi Henry,

You're not missing anything.  That will work.  Did you download the 6.45 pre-release?  Perhaps there is a syntax error somewhere else in your config file.  I suggest taking a new copy of the original config file and changing just 'NewXMPxmpTag' to 'Volume'.

Oh.  And did you remember to copy the config file to ".ExifTool_config" in your home directory?  (note the "." at the start of the file name.)  ExifTool looks in your home directory for the config file.

- Phil

Archive

[Originally posted by panday on 2006-10-03 14:34:01-07]

Hello Phil!

I was able to finally make it work. However, it seems the config file needs to be placed where my script is placed and not in the home directory

Anyway, thank you very much for all the help.

- Henry Santyana

Archive

[Originally posted by exiftool on 2006-10-03 17:05:24-07]

Hi Henry,

I'm glad you figured it out.

This would happen if your HOME environment variable is not set.  What shell are you using?
All Unix shells I know set this, but I don't know about the Windows cmd shell.

The logic is as follows:

If the EXIFTOOL_HOME environment variable is set, ExifTool looks there for the config file.
Otherwise, it looks in your HOME directory.  If neither EXIFTOOL_HOME or HOME are set,
then  ExifTool defaults to using the current directory.

- Phil

Archive

[Originally posted by exiftool on 2006-10-03 23:09:49-07]

I just tested this on a Windows machine, and HOME is not set in the
cmd shell environment.  However, HOMEDRIVE and HOMEPATH are,
so I will add the ability to use these if neither EXIFTOOL_HOME nor
HOME is available.  This feature will appear in 6.45 when it is released.

- Phil