Support for IPTC

surge_martin - December 30, 2008 - 14:33
Project:Imagefield Import
Version:6.x-1.3-beta1
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:postponed (maintainer needs more info)
Description

It would be great this module could access the metadata for pictures, and use it for titles, etc.

#1

basicmagic.net - February 3, 2009 - 06:04

subscribe

#2

hedinfoto - February 8, 2009 - 01:38

In the for each loop add the following under the:
foreach ($files as $file) {

Add:

$image_name = $dirpath . '/' . basename($file->filename);
$size = getimagesize($image_name, $info);
if(isset($info['APP13']))
{
    $iptc = iptcparse($info['APP13']);
    $caption = $iptc["2#120"][0];
}
else {
$caption = basename($file->name);
}

Replace:
$form['files']['title'][] = array(          '#type' => 'textfield',          '#size' => 20,          '#default_value' => basename($file->name),        );

With:
$form['files']['title'][] = array(          '#type' => 'textfield',          '#size' => 20,          '#default_value' => $caption,        );

This will use the iptc caption for the title.

This is on the drupal 6 version.

#3

vordude - March 6, 2009 - 01:57
Status:active» postponed (maintainer needs more info)

Sorry for my ignorance on IPTC--

Do all images have such metadata?

How is the caption usually used?

Would that make a more suitable body?

#4

sodome - March 6, 2009 - 22:05

To my knowledge, most image formats have some capacity to store metadata. TIFF, RAW and jpg seem the image formats most widely read from & written to. IPTC is one of a few standards by which the data's written. There isn't a lot of consistency between software support for individual metatags or which tags are written by which cameras, but they all write something that identifies variables of the image origination, and many allow further user modifications, eg user comments, keyword insertion, copyright data, etc.. The caption is used differently in different contexts, but is more flexible than some IPTC tags in that it can hold more characters.

The EXIF module (http://drupal.org/node/226703) provides some strong image metadata-reading functions, but I haven't yet been able to configure it to read the fields I need. I've also been revisiting hedinfoto's caption solution above, trying to adapt it to gather keywords, but the coding is beyond me so far.

For me, the most powerful application of harvesting metadata at the image bulk upload stage would be to allow an interface between metadata content and other drupal entities, eg importing keywords or comments and mapping those to selected taxonomies, as the maqum module (http://drupal.org/project/maqum) currently does for single taxonomies on single images, or importing subject fields and mapping them to user references.

Totally thrilled to see you examining this area. If there are ways an image geek much more comfortable on the camera end can support/assist/encourage development, please let me know.
Thanks!

#5

wentsch - March 30, 2009 - 14:44

Subscribing.
Could really need iptc support for d6 as this is what keeps me chained to d5 (with maqum) currently.

#6

photonyx - April 1, 2009 - 09:04
Category:feature request» support request

The following works for me. The caption of the image goes into the Title and the keywords go into the Body.

$size = getimagesize($dirpath.'/'.basename($file->filename), $info);
if(isset($info['APP13']))
{
    $iptc = iptcparse($info['APP13']);
    // Key 2#120 is the caption
    $caption = $iptc["2#120"][0];
    // Key 2#025 is the keywords (not sure if this is true only for Photoshop)
    $keywords =  implode(', ',$iptc["2#025"]);
}
else {
$caption = basename($file->name);
$keywords = " ";
}
      // image_get_info is a Drupal Function That Gets Details about an image

The last line is given to anchor the code

The second snippet is straightforward assignment of the Title and Body fields:

        $form['files']['title'][] = array('#type' => 'textfield', '#size' => 20, '#default_value' => $caption, );
        $form['files']['body'][]  = array('#type' => 'textfield', '#size' => 20, '#default_value' => $keywords, );

@vordude:

Caption and Keywords are usually used on photo sites that have large number of contributors that upload large batches of files. Typically the node is given the title from the caption field and keywords are used for the database search. Typical sites that need this are photos stock sites such as istockphoto.com

It would be great to extend the given code snippet to automatically create a node type that has several text fields corresponding to EXIF/IPTC fields.

Hope this helps.

#7

dquakenbush - April 29, 2009 - 15:17
Title:Support for IPTC» more metadata

This works really well.
We have metadata in a lot of fields -- here's a little script I found that translates various fields into their IPTC codes.
Set up an image in photoshop (or wherever) with your metadata, then feed it to this script. It'll tell you what "2#xyz" keys match the fields you use.

<html>
<head>
<title>Metadata Checker</title>
</head>

<body>

<?php
function output_iptc_data( $image_path ) {  
   
$size = getimagesize ( $image_path, $info);      
     if(
is_array($info)) {  
       
$iptc = iptcparse($info["APP13"]);
        foreach (
array_keys($iptc) as $s) {            
           
$c = count ($iptc[$s]);
            for (
$i=0; $i <$c; $i++)
            {
                echo
$s.' = '.$iptc[$s][$i].'<br>';
            }
        }                
    }           
}


$image_path = "/server/path/to/the/image/with/metadata/in/it/.jpg";

output_iptc_data($image_path);


?>



</body>
</html>

#8

dquakenbush - April 29, 2009 - 15:21
Title:more metadata» Support for IPTC

#9

rubberglove - May 4, 2009 - 16:05

How funny, just the other day I put together a similar patch for myself...

Instead of putting keywords into the body field, however, I wanted to put (IPTC) keywords into (taxonomy) Tags.
As well, it reads the EXIF 'DateTime' into a cck date field.... and, because I don't want duplicates it will ignore filenames that already exist (rather than renaming them).

Basically it adds a 'tags' text field to each row of the import form, and populates it based on the iptc keywords. This list is appended to the taxonomy field already present on the form (so that a tag can be added to the entire batch of files).

I'm attaching the patch for reference only, in case anyone feels like putting together a system like this on their own, but note that some things (like the taxonomy vocabulary, the name of the CCK date field and files location) are hardcoded, and it uses things like $_SERVER['DOCUMENT_ROOT'], to find directories, which is most probably not the drupal way of getting the base path...

But this system is working great for me for images that my lady friend tags using iPhoto. Using taxonomy makes it simple to put together galleries based on views (I use jquery/galleria for this), and I like having the date that the photo was taken stored as well.

Also, I consistently get warnings of invalid values from the exif_read_data function, but this doesn't seem to cause any problems, and might just be a bug in php http://bugs.php.net/bug.php?id=40073 or in the exif data that my camera puts out.

cheers.

edit: I think it would be great if some EXIF and IPTC data was read in by the core image_get_info function()...

#10

wentsch - May 11, 2009 - 13:22

Hey rubberglove,

that sounds really useful and I'd like to see your code for reference, as I'm gonna need something similar sooner or later, too.
Did you forget to attach your patch? Can't see it.

Thanks in advance,
Daniel

#11

tstermitz - June 9, 2009 - 16:32

EXIF and IPTC are related enough that people use them interchangeably and generically to refer to image metadata.

Somewhat more specifically, these names represent families of image metadata tags: The camera itself usually populates EXIF, and you can use editing programs like Graphic Converter or Nikon's View NX to edit IPTC. This latter set of tags is more consistently used than EXIF because journalists and newspapers need a consistent way of labeling and tracking media. In addition, the XMP family of tags is often used by other programs like photoshop or windows applications, but here again, each application extends and adds additional tags. (Not to mention re-use and over-writing of tags named the same in different families).

The IPTC defines a keywords field. I use the contact field as a secondary taxonomy vocabulary to tag people or places. I use various other IPTC fields more-or-less as defined, but sometimes I redefine them for my own purposes.

ALL PRESENT DRUPAL IMAGE MODULES ARE BAD AT READING EXIF DATA

The php exifread function doesn't seem to be very forgiving, but is commonly used because it is available on many (most?) hosting sites. I've abandoned it because I get bad characters and strange entries coming out of my meta tags, which have been edited on an apple. I haven't tried the iptc parse, yet. Instead, I use exiftool to dump my tags to a sidecar file.

The perl utility: exiftool is EXTREMELY robust and very well-maintained. You can examine tags and tag families. It let's you read or write any of your tags and it is scriptable so you can do bulk tag editing across your photographs.

Also, exiftool lets you can dump any or all of your photo tags to a sidecar file in various formats like: tag:value, JSON or XMP. Building a sidecar file may seem like additional hassle, but if you are uploading via ftp, then there is no problem in bringing along additional text files.

Hint1: php has decent read functions for JSON encoded data....
Hint2: fast_gallery automatically builds, updates and deletes galleries out of folders.
Hint3: It is not integrated with nodes or image_field

http://PhotoKinesis.US

#12

rubberglove - August 18, 2009 - 22:58

ah - not only did I forget to attach my patch (or so it seems), but I got busy and forgot to check back here...
apologies for the delay, hopefully this could still be useful...

AttachmentSize
iptc_tags.patch 7.02 KB

#13

arhak - September 15, 2009 - 05:56

I have developed a module which brings API functions for IPTC metadata support (even encoding handling/conversions)
But I won't be able to contribute it since I can't use CVS due to firewall restrictions

If you read my forum post Looking for a CVS committer you can find apix_iptc listed

If somebody comes up with some idea I would gladly contribute it, maintain it and give support for other module developers which might wan't to use its API

 
 

Drupal is a registered trademark of Dries Buytaert.