Mail Index


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ApacheGallery] Image::IPTC info handling



One of my key image handling pieces in my photography "workflow" is to
edit the IPTC information.  This is a standard settled on by the
News/Press industry for image meta data like author, event title,
location, people  (contacts), keywords, caption, etc.  This works like
ID3 inside an MP3 and alongside EXIF.  Here's a patch that allows you
to access that data from within A::G.  Note that you now need to have
Image::IPTC installed on the server.  You can see how I make use of
this at 

   http://home.lathi.net/gallery/2004/11-November/Misc/IMG_1454.JPG

Another thing I did was add a global variable GalleryListSep as a
string to separate list items.  As is, list items in EXIF are just
joined with " " (and that's the default with this patch).  Since stuff
like contacts and keywords are also lists, I wanted to join them with
something nicer.  So, I set my GalleryListSep to ', ' in my
httpd.conf.

Here's the patch:

--- Apache-Gallery-0.9.1/lib/Apache/Gallery.pm	Sat Sep 11 17:53:05 2004
+++ Apache-Gallery-devel/lib/Apache/Gallery.pm	Thu Dec  9 11:56:58 2004
@@ -39,9 +40,10 @@
 		Apache::Constants->import('OK','DECLINED','FORBIDDEN','NOT_FOUND');
 
 	}
 }
 
 use Image::Info qw(image_info);
+use Image::IPTCInfo;
 use Image::Size qw(imgsize);
 use Image::Imlib2;
 use Text::Template qw(fill_in_file);
@@ -57,7 +60,8 @@
 
 # Regexp for escaping URI's
 my $escape_rule = "^A-Za-z0-9\-_.!~*'()\/";
 my $memoized;
+my $list_sep;
 
 sub handler {
 
@@ -155,6 +163,8 @@
 	my $uri = $r->uri;
 	$uri =~ s/\/$//;
 
+        $list_sep = $r->dir_config('GalleryListSep') || " ";
+
 	unless (-f $filename or -d $filename) {
 		show_error($r, 404, "404!", "No such file or directory: ".uri_escape($r->uri, $escape_rule));
 		return $::MP2 ? Apache::OK() : Apache::Constants::OK();
@@ -1014,15 +1062,22 @@
 		# info using Image::Info
 		elsif (grep $type eq $_, qw(JPG)) {
 			# Only for files that natively keep the EXIF info in the same file
-			$imageinfo = image_info($file);
+                    my $iptc = new Image::IPTCInfo($file);
+                    if ($iptc) {
+                        foreach my $key (keys %{$iptc->{_listdata}}, keys %{$iptc->{_data}}) {
+                            $imageinfo->{$key} = $iptc->{_listdata}->{$key};
+                        }
+                        foreach my $key (keys %{$iptc->{_data}}) {
+                            $imageinfo->{$key} = $iptc->{_data}->{$key};
+                        }
+                    }
 		}
 	}
-
 	unless (defined($imageinfo->{width}) and defined($imageinfo->{height})) {
 		$imageinfo->{width} = $width;
 		$imageinfo->{height} = $height;
 	}
 
 	foreach (@infos) {
 		
 		my ($human_key, $exif_key) = (split " => ")[0,1];
@@ -1036,22 +1099,25 @@
 				foreach my $element (@{$imageinfo->{$exif_key}}) {
 					if (ref($element) eq 'ARRAY') {
 						foreach (@{$element}) {
-							$value .= $_ . ' ';
+							$value .= $_ . $list_sep;
 						}
+                                                $value =~ s/$list_sep$//;
 					} 
 					elsif (ref($element) eq 'HASH') {
-						$value .= "<br>{ ";
-			    		foreach (sort keys %{$element}) {
-							$value .= "$_ = " . $element->{$_} . ' ';
-						}
-			    		$value .= "} ";
-					} 
+                                            $value .= "<br>{ ";
+                                            foreach (sort keys %{$element}) {
+                                                $value .= "$_ = " . $element->{$_} . $list_sep;
+                                            }
+                                            $value =~ s/$list_sep$//;
+                                            $value .= "} ";
+					}
 					else {
 						$value .= $element;
 					}
-					$value .= ' ';
+					$value .= $list_sep;
 				}
-			} 
+                                $value =~ s/$list_sep$//;
+			}
 			else {
 				my $exif_value = $imageinfo->{$exif_key};
 				if ($human_key eq 'Flash' && $exif_value =~ m/\d/) {
@@ -1205,6 +1271,15 @@
 			elsif ($imageinfo->{Orientation} eq 'left_bot') {
 				$rotate=3;
 			}
+                        elsif ($imageinfo->{Orientation} =~ m'Normal'i) {
+                            $rotate = 0;
+                        }
+                        elsif ($imageinfo->{Orientation} =~  m'90 CCW') {
+                            $rotate = 3;
+                        }
+                        elsif ($imageinfo->{Orientation} -~ m'90 CW') {
+                            $rotate = 1;
+                        }
 		}
 	}
 
@@ -1710,6 +1785,14 @@
 
 Set this option to 1 to convert underscores to spaces in the listing
 of directory names.
+
+=item B<GalleryListSep>
+
+This should be the character sequence to use as a list separator.  The
+default is ' '.  This separator will only be used between values.  In
+other words, the final separator isn't added to the list of values.
+
+=back
 
 =head1 FEATURES
 
--
doug@xxxxxxxxx