Read Keywords from JPG

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
brethomp

Read Keywords from JPG

Post by brethomp »

I'm using the ImageMagickObject in a classic ASP environment. What I would like to do is read the keywords that other programs have put in there (like Adobe Bridge and Picasa) out of JPG files . With TIF files I have it working, using "identify" and "%[IPTC:2:25]", but with JPG files this field seems to be blank, unless the JPG originated from a TIF that had keywords in it. Where can I find the keywords in JPG files?

ImageMagick-6.6.2-3-Q16
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Read Keywords from JPG

Post by magick »

The metadata in JPEG image files are typically encoded in the EXIF profile rather than IPTC.
brethomp

Re: Read Keywords from JPG

Post by brethomp »

Thanks for the reply. I couldn't find any keywords in the EXIF data. I built a loop to go through all of the EXIF "tags" that are listed on this site http://www.imagemagick.org/script/escape.php. Are there other EXIF "tags" that the keywords could be under? I did also try %[EXIF:*], and didn't see any keywords there either.
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Read Keywords from JPG

Post by Drarakel »

Are you sure that your JPG file contains the keywords?
You can use "identify -verbose file.jpg" to display most of the metadata.
brethomp

Re: Read Keywords from JPG

Post by brethomp »

Yep, there are definitely keywords in the files, since Adobe Bridge can see them. Further research is leading me to believe that the keywords I am looking for are not stored in EXIF or IPTC. It appears that Adobe and Microsoft have a different place to store them called XMP. Can ImageMagick read XMP?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Read Keywords from JPG

Post by snibgo »

convert in.jpg out.xmp
snibgo's IM pages: im.snibgo.com
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Read Keywords from JPG

Post by Bonzo »

We might be looking at the same brethomp thing see viewtopic.php?f=1&t=16454

How did you input your keywords ?

If you open the image in a program like Notepad++ or a hex editor are they in an XML portion at the end of the file ?
brethomp

Re: Read Keywords from JPG

Post by brethomp »

Bonzo,

Yes, if I open the JPG images in Notepad, I can find my keywords in the file. They are in a XML looking portion of the file, but in my case near the beginning of the file. In this format:

Code: Select all

<dc:subject>
    <rdf:Bag>
        <rdf:li>Keyword 1</rdf:li>
        <rdf:li>Keyword 2</rdf:li>
        <rdf:li>Keyword 3</rdf:li>
    <rdf:Bag>
</dc:Subject>
Edit: I missed one of your questions. The keywords were entered using Adobe Bridge.
Last edited by brethomp on 2010-06-18T05:49:32-07:00, edited 3 times in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Read Keywords from JPG

Post by snibgo »

Post a sample.
snibgo's IM pages: im.snibgo.com
brethomp

Re: Read Keywords from JPG

Post by brethomp »

snibgo wrote:Post a sample.
Is it possible to post files on this forum?
brethomp

Re: Read Keywords from JPG

Post by brethomp »

snibgo wrote:convert in.jpg out.xmp
Thanks snibgo, this works, but not optimal. The resulting "out.xmp" file is a text file containing only the XMP metadata. Now I just have to parse the XMP file to get the keywords...
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Read Keywords from JPG

Post by Drarakel »

brethomp wrote:Is it possible to post files on this forum?
Don't think so - at least not as fresh user.(?)
FAQ
But you could use one of the various file hosting sites.
brethomp

Re: Read Keywords from JPG

Post by brethomp »

snibgo wrote:convert in.jpg out.xmp
This method only seems to work with JPG files.
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Read Keywords from JPG

Post by Drarakel »

No, it works with other formats, too - TIF/PNG/etc. But it's possible for some special files that a certain profile isn't recognized.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Read Keywords from JPG

Post by Bonzo »

It worked with a jpg file where the data was around line 54 but not on a CR2 file where the data was at the end on line 186187. Both lots of data were added to the image using Microsoft pro photo tools. No idea why my data was in the image or at the end and and brethomp had his at the start.

I have not had any experiance of this but thought an xmp file was a file linked to and image not part of the image file. Will need some more investigation.
Post Reply