IPTC to caption/keywords support (patch for 1.3.3)

tistre
tistre's picture

Joined: 2003-02-13
Posts: 2
Posted: Thu, 2003-02-13 12:04

Hi there,

Gallery is great, but my carefully crafted IPTC metadata was lost when I added my JPEGs to the Gallery.

So I hacked IPTC support (for picture import) into the 1.3.3 sources - works great and shouldn't have any negative side effects.

I don't know how the patch will display in this forum - just mail me (at

) if I should send it to you by e-mail.

<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE>
diff -ru gallery-1.3.3/classes/Album.php gallery-iptcpatch/classes/Album.php
--- gallery-1.3.3/classes/Album.php Sat Dec 7 08:26:17 2002
+++ gallery-iptcpatch/classes/Album.php Thu Feb 13 12:38:55 2003
@@ -604,7 +604,36 @@
}
return $err;
} else {
+ // Add IPTC HEADLINE + CAPTION to caption
+
+ $iptc = $item->getIPTC($dir, $name, $tag);
+
+ if (isset($iptc[ "HEADLINE" ]))
+ { if ($caption != '') $caption .= '<br />';
+ $caption .= '<b>' . htmlspecialchars($iptc[ "HEADLINE" ]) . '</b>';
+ }
+
+ if (isset($iptc[ "CAPTION" ]))
+ { if ($caption != '') $caption .= '<br />';
+ $caption .= htmlspecialchars($iptc[ "CAPTION" ]);
+ }
+
$item->setCaption("$caption");
+
+ // Put additional IPTC data into keywords
+
+ $kw = '';
+
+ foreach ($iptc as $iptctag => $iptcvalue)
+ { if (($iptctag == 'HEADLINE') || ($iptctag == 'CAPTION'))
+ continue;
+
+ if ($kw != '') $kw .= ' ';
+ $kw .= $iptcvalue;
+ }
+
+ $item->setKeywords($kw);
+
$originalItemCaptureDate = getItemCaptureDate($file);
$now = time();
$item->setItemCaptureDate($originalItemCaptureDate);
diff -ru gallery-1.3.3/classes/AlbumItem.php gallery-iptcpatch/classes/AlbumItem.php
--- gallery-1.3.3/classes/AlbumItem.php Wed Nov 27 08:59:31 2002
+++ gallery-iptcpatch/classes/AlbumItem.php Thu Feb 13 12:38:55 2003
@@ -347,6 +347,89 @@
return $ret;
}

+ function getIPTC($dir, $name, $tag) {
+
+ $result = array();
+
+ $filename = $dir . "/" . $name . "." . $tag;
+ getimagesize($filename, $imgsize);
+
+ if (! is_array($imgsize))
+ return $result;
+
+ if (! isset($imgsize[ 'APP13' ]))
+ return $result;
+
+ $iptc = iptcparse($imgsize[ 'APP13' ]);
+
+ if (! is_array($iptc))
+ return $result;
+
+ $iptcmap = array(
+ '1#070' => 'DATESENT',
+ '1#080' => 'TIMESENT',
+ '2#005' => 'OBJECTNAME',
+ '2#007' => 'EDITSTATUS',
+ '2#010' => 'URGENCY',
+ '2#015' => 'CATEGORY',
+ '2#020' => 'SUBCATEGORY',
+ '2#022' => 'FIXTURE',
+ '2#025' => 'KEYWORD',
+ '2#030' => 'RELDATE',
+ '2#035' => 'RELTIME',
+ '2#040' => 'SPECINSTR',
+ '2#055' => 'CREDATE',
+ '2#060' => 'CRETIME',
+ '2#065' => 'ORGPRG',
+ '2#070' => 'PRGVER',
+ '2#080' => 'BYLINE',
+ '2#085' => 'BYTITLE',
+ '2#090' => 'CITY',
+ '2#092' => 'SUBLOCATION',
+ '2#095' => 'STATE',
+ '2#100' => 'COUNTRYCODE',
+ '2#101' => 'COUNTRYNAME',
+ '2#103' => 'ORGTRANSREF',
+ '2#105' => 'HEADLINE',
+ '2#110' => 'CREDIT',
+ '2#115' => 'SOURCE',
+ '2#116' => 'COPYRIGHT',
+ '2#118' => 'CONTACT',
+ '2#120' => 'CAPTION',
+ '2#122' => 'CAPTIONWRITER',
+ '2#130' => 'IMAGETYPE',
+ '2#131' => 'ORIENTATION',
+ '2#135' => 'LANGUAGE',
+ '8#010' => 'SUBFILE',
+ '2#199' => 'APPRESERVER'
+ );
+
+ foreach ($iptc as $pos => $values)
+ foreach ($values as $value)
+ { if (! isset($iptcmap[ $pos ]))
+ continue;
+
+ // strip leading zeros (weird Kodak Scanner software)
+ while ($value[ 0 ] == chr(0))
+ $value = substr($value, 1);
+
+ // remove binary nulls
+ $value = str_replace(chr(0x00), ' ', $value);
+
+ if (trim($value) == '')
+ continue;
+
+ if (isset($result[ $iptcmap[ $pos ] ]))
+ $result[ $iptcmap[ $pos ] ] .= ' ';
+ else
+ $result[ $iptcmap[ $pos ] ] = '';
+
+ $result[ $iptcmap[ $pos ] ] .= $value;
+ }
+
+ return $result;
+ }
+
function makeThumbnail($dir, $thumb_size, $pathToThumb="")
{
global $gallery;
</TD></TR></TABLE><!-- BBCode End -->

 
alindeman
alindeman's picture

Joined: 2002-10-06
Posts: 8194
Posted: Thu, 2003-02-13 22:35

You might consider sending this to the gallery-devel mailing list. It will get noticed faster.

 
beckett
beckett's picture

Joined: 2002-08-16
Posts: 3474
Posted: Fri, 2003-02-14 07:41

I'd like to see this in a working gallery. Can you provide a URL? Is this something many people are interested in?

 
Eelco
Eelco's picture

Joined: 2003-02-12
Posts: 4
Posted: Thu, 2003-02-20 13:26

How do I implement this IPTC into my gallery?
Or is this a upcoming feature in a next release?

I noticed that more and more applications use IPTC...

 
alindeman
alindeman's picture

Joined: 2002-10-06
Posts: 8194
Posted: Thu, 2003-02-20 21:58

You can use the patch utility to patch your Gallery.

 
tistre
tistre's picture

Joined: 2003-02-13
Posts: 2
Posted: Mon, 2003-02-24 12:38

I have now created a homepage for this patch. Downloads and instructions are available here:

<!-- BBCode Start --><A HREF="http://tim.digicol.de/gallery_iptc/" TARGET="_blank">http://tim.digicol.de/gallery_iptc/</A><!-- BBCode End -->

 
alindeman
alindeman's picture

Joined: 2002-10-06
Posts: 8194
Posted: Mon, 2003-02-24 23:26

Very nice instructions. Beckett, the current maintainer of G1, is on travel right now, but it should get noticed after he gets back.

 
blixer

Joined: 2003-03-10
Posts: 2
Posted: Mon, 2003-03-10 14:19

Great patch!!

This is something that I've been looking for for a while.

If I were the maintainer of Gallery, I would transfer as much of the information about an image into the image itself - its the logical place to store it and makes it a simple matter to move images between various places.

I'd love to see Gallery able to fully edit the IPTC info, choose what parts are displayed along with the image, enable searching based upon it etc.

Like Andrew, I have a strict system for naming all my jpegs and this prevents me from manually captioning images whenever I upload to gallery :smile:

Thanks again - I hope this appears in Gallery 1.3.4 :smile:

Tristan.

 
JeremyCherfas

Joined: 2003-06-02
Posts: 4
Posted: Mon, 2003-06-02 19:20

I'm delighted to have discovered Gallery and especially the possibility of using IPTC information that I have embedded in my JPEGs. But I have a problem. After downloading the patches I get

Fatal error: Call to undefined function: getextrafields() in /Users/Shared/Web80/gallery/view_album.php on line 260

I've tried to find similar errors in the Forums with no luck.

Can anybody please help?

Thanks

Jeremy

 
joan
joan's picture

Joined: 2002-10-21
Posts: 3473
Posted: Mon, 2003-06-02 20:56

Which version did you patch? 1.3.3 or 1.3.4?

 
joan
joan's picture

Joined: 2002-10-21
Posts: 3473
Posted: Mon, 2003-06-02 21:00

Which version did you patch? 1.3.3 or 1.3.4? Have you applied any other patches?

 
JeremyCherfas

Joined: 2003-06-02
Posts: 4
Posted: Tue, 2003-06-03 04:35

I think it was 1.3.4 -- the latest version, which I downloaded yesterday. And no, I've made no other patches. But I did ask for some additional keywords when I configured Gallery. Could that be it? If so, how do I get rid of them?

Jeremy

 
joan
joan's picture

Joined: 2002-10-21
Posts: 3473
Posted: Tue, 2003-06-03 06:54

see, this patch was written against 1.3.3. There have been a lot of changes, so it may not work against 1.3.4. Apparently it doesn't

Two choices:
1) fix it, and publish the new patch here.
2) use 1.3.3 and wait until someone else updates this patch, then upgrade to 1.3.4 and patch it.
**UPDATE**
3) or wait for 1.3.5, which should have this built in. No ETA yet on that.

 
dave_spa

Joined: 2003-06-17
Posts: 2
Posted: Thu, 2009-06-25 10:29

.

 
tbishop61

Joined: 2003-06-23
Posts: 16
Posted: Mon, 2003-06-23 17:15

I love the IPTC patch that I applied to Gallery 1.3.3. It made Gallery twice as useful!

But how do I upgrade Gallery to Release 1.3.4 without losing the ITPC suport. The site mentioned above by dave_spa doesn't seem to be reachable.

Thanks,
Tim

 
sagemaniac

Joined: 2003-03-26
Posts: 47
Posted: Tue, 2003-07-08 00:12
tistre wrote:
I have now created a homepage for this patch. Downloads and instructions are available here:

http://tim.digicol.de/gallery_iptc/

Thanks tistre,

I've copied your lines into the relevant gallery 1.3.5 files - seems to work.
It would be nice though, to have other IPTC info show up in the exif window...