How do I replace the IPTCT metadata

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
martinto
Posts: 2
Joined: 2011-08-22T01:33:22-07:00
Authentication code: 8675308

How do I replace the IPTCT metadata

Post by martinto » 2011-08-22T01:41:42-07:00

I am attempting to remove the existing IPTC metadata from an image and then add my own so that I can set author, byline and copyright information.

I am programming in Delphi and have succeeded in reading in an image, resizing it, and then writing it back out to a new location so I am calling the ImageMagick API successfully. It is the IPTC meta data which is defeating me. Here is what I have written in my code:

Code: Select all

  pansi := MagickRemoveImageProfile(Wand, PAnsiChar('IPTC'), @len);
  if pansi = nil then
    Exit;
  Result := MagickSetImageProfile(Wand, PAnsiChar('IPTC'), @IPTC[0], length(IPTC)) = MagickTrue;
I have proved this works in that when I remove the profile the count of profiles goes down by one. The contents of the profile returned by MagickRemoveImageProfile() are correct (they contain the original data). The IPTC array contains my new metadata, I can read that back using GetImageProfile() and it contains the new data. However, when I save the file it still contains the original data.

This is how I write the file:

Code: Select all

Result := MagickWriteImages(Wand, PAnsiChar(AnsiName), MagickFalse) = MagickTrue;
Where am I going wrong?

martinto
Posts: 2
Joined: 2011-08-22T01:33:22-07:00
Authentication code: 8675308

Re: How do I replace the IPTCT metadata

Post by martinto » 2011-08-22T08:53:23-07:00

I have cracked it! Photoshop uses XMP as well as IPTC metadata, and I should use 8BIM and not IPTC so this is the result:

Code: Select all

pansi := MagickRemoveImageProfile(Wand, PAnsiChar('XMP'), @len);
pansi := MagickRemoveImageProfile(Wand, PAnsiChar('8BIM'), @len);
if pansi = nil then
  Exit;
Result := MagickSetImageProfile(Wand, PAnsiChar('8BIM'), @IPTC[0], length(IPTC)) = MagickTrue;
Or using convert:

Code: Select all

convert in.jpg +profile XMP +profile 8BIM -profile 8BIMTEXT:data.iptc out.jpg

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How do I replace the IPTCT metadata

Post by anthony » 2011-08-23T17:45:39-07:00

One point about you convert line...

IM is a general image processor, it will always decode and encode (read-write image data) any JPEG images it works with, which is a lossy operation. that is you will loose quality in your JPEG image! This can not be helped!

The profile handling in IM is ment to be applied during other image processing operations, not just for the sake of profile changes.

As such if you only want to make profile changes, then IM is not the right tool, and you should look at some other 'loss-less JPEG handling' tool for JUST profile substitutions.

Of course if you don't care. Fine. No problem :-)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Post Reply