Retrieving captions from EXIF automatically?

swaits

Joined: 2003-03-06
Posts: 4
Posted: Thu, 2003-03-06 09:04

I use Adobe Photoshop Album to categorize and manage all of my images on my PC. If I add captions to images in this application, they are stored in the EXIF of each image. 'jhead -v image.jpg' outputs it as "ImageDescription".

I'd like to know if anyone has gotten PHP Gallery to automatically set image captions to this EXIF field when uploading/importing?

Thanks,
Steve

Login or register to post comments
phgrove

Joined: 2002-10-10
Posts: 98
Posted: Thu, 2003-03-06 12:18

I had the same problem. 2000 photos with a comment in the EXIF field that i wanted as a caption. When i get home i will post the code for you.

Peter

Login or register to post comments
swaits

Joined: 2003-03-06
Posts: 4
Posted: Thu, 2003-03-06 16:47

Oh dude that would be fantastic! It doesn't look like it'd be too difficult to hack in, but I really look forward to getting your code :smile:

Thanks!

--Steve

Login or register to post comments
IlyZislin

Joined: 2003-02-01
Posts: 3
Posted: Thu, 2003-03-06 22:04

email me at ILYZISLIN at AOL dot COM and I will send you the files to do it.

--Ily.

Login or register to post comments
swaits

Joined: 2003-03-06
Posts: 4
Posted: Fri, 2003-03-07 01:34
Quote:
email me at ILYZISLIN at AOL dot COM and I will send you the files to do it..

Ok, I emailed you, thanks!

--Steve

Login or register to post comments
Gaile

Joined: 2002-07-20
Posts: 1301
Posted: Fri, 2003-03-07 04:03

Would you mind sharing the code here so that everyone could benefit?

Thanks!

Gaile

Login or register to post comments
phgrove

Joined: 2002-10-10
Posts: 98
Posted: Fri, 2003-03-07 08:06

replace lines 326 to 329 in the save_photos.php fiel withthe following. Replace comment with any other EXIF feidl you want as the caption. If you tick the box when saving pictures it will use the file name, else it will try and get the EXIF comment field data.

<!-- 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> msg("- Adding $name");
if ($setCaption) {
$caption = $originalFilename;
} else {
list($status, $myExif) = getExif($file);
if ($myExif) {
// following line commented out because we were losing
// comments from the Exif array. This is probably due
// to differences in versions of jhead.
// array_pop($myExif); // get rid of empty element at end
array_shift($myExif); // get rid of file name at beginning
while (list($key, $value) = each ($myExif)) {
if ($key == "Comment") {
$caption = $value;
}
}
} else {
$caption = "";
}
} </TD></TR></TABLE><!-- BBCode End -->

Login or register to post comments
ts
ts's picture

Joined: 2003-03-27
Posts: 2
Posted: Thu, 2003-03-27 02:41

I've been playing with this same problem. Turns out Photoshop Album puts the caption in, and calls it ImageDescription. What's more, it's not in the base EXIF, at least in the pictures that I'm working with, it's in some other part of the tags, only accessible by "jhead -v".

So, I tried this code, but it didn't work. Then I tried replacing "jhead" with "jhead -v" in my config. That didn't work, because jhead puts an "=" instead of a ":" between ImageDescription and the caption. So, I rewrote the code:

<!-- 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>
msg("- Adding $name");
if ($setCaption) {
$caption = $originalFilename;
} else {
$caption = "";
global $gallery;
$path = $gallery->app->use_exif;
list($return, $status) = exec_internal(fs_import_filename($path, 1) .
" -v " .
fs_import_filename($file, 1));

if ($status == 0) {
while (list($key,$value) = each ($return)) {
$explodeReturn = explode('=', $value, 2);
if (trim($explodeReturn[0]) == "ImageDescription") {
$caption = substr(trim($explodeReturn[1]),1,-2);
msg("- Setting caption to: $caption");
}
}
}
}

</TD></TR></TABLE><!-- BBCode End -->

Note several ugly hacks:
I hard-coded the "-v" for jhead. Probably won't work with anything else that retrieves EXIF info.
I also trim off one character from the front and two from the end, to get rid of quotes and some random question mark that appears at the end of each caption.

In any case, I can now caption things in Photoshop Album, and import them to Gallery with the captions intact. Cool! Hope this helps other folks.

-ts-

Login or register to post comments
gcrocker

Joined: 2003-07-29
Posts: 1
Posted: Tue, 2003-07-29 16:28

For version 1.3.4, the above patch is in util.php, line 1468:

			processingMsg("- Adding $name");

			if ($setCaption) {
					$caption = $originalFilename;
			} else {
					$caption = "";
					global $gallery;
					$path = $gallery->app->use_exif;
					list($return, $status) = exec_internal(fs_import_filename($path, 1) .
															" -v " .
															fs_import_filename($file, 1));

					if ($status == 0) {
							while (list($key,$value) = each ($return)) {
								$explodeReturn = explode('=', $value, 2);
								if (trim($explodeReturn[0]) == "ImageDescription") {
									$caption = substr(trim($explodeReturn[1]),1,-2);
									processingMsg("- Setting caption to: $caption");
								}
							}
					}
			}

-glenn

Login or register to post comments
FrankTek

Joined: 2004-01-04
Posts: 1
Posted: Sun, 2004-01-04 22:47

ts or phgrove:
I'm trying to integrate your exif caption tweaks into Gallery 1.4.1; but the save_photos.php must have changed significantly since your posts since I can't find the spot to make your suggested code replacements. Does anyone have any suggestions for making these modifications to Gallery 1.4.1?
Thanks,
Frank

Login or register to post comments
raymondau
raymondau's picture

Joined: 2004-01-11
Posts: 5
Posted: Thu, 2004-01-15 20:17

i have the same problems with this :evil:

hope somebody can help :wink:

thx a lots

Login or register to post comments
dotvicky

Joined: 2004-05-25
Posts: 34
Posted: Tue, 2005-06-14 08:45

Hiya,

Bumping this as this is the problem I'm having.

I'm currently on 1.5.

Cheers
Vicky

Login or register to post comments