Jump to content

Issue extracting EXIF UserComment


brettjrob

Recommended Posts

I am new to PHP, just purchased paid hosting for the first time, and I'm working on creating a basic PHP photo gallery. The gallery portion seems to be working well at this point (displaying a thumbnail and link for each photo inside a directory), but the page to display an individual photo is giving me quite the headache. What I wanted to do was extract a few EXIF properties from each JPG file to write onto the page... I had no trouble doing so using exif_read_data() to get the date and certain camera settings, but when I attempt to print the UserComment field, I get a jarbled mess in Firefox (but not IE).

After some searching and testing, I believe there is an issue with the character encoding of the string PHP is returning me. The EXIF UserComment field for each of my JPG files contains a comment string in Unicode, and evidently there is some issue when retrieving it through the following code:

[code]<? $exif = exif_read_data($fileloc, 0, true);

$computedvals = $exif['COMPUTED'];

$caption = $computedvals['UserComment']; ?>
<html><body>
<? echo ($caption); ?>
</body><html>[/code]

Here is an example of the output I'm getting:

[a href=\"http://www.skyinmotion.com/viewphoto.php?gallery=Landscape&filepath=http://www.skyinmotion.com/photos/landscape&filename=CRW_5054.jpg\" target=\"_blank\"]http://www.skyinmotion.com/viewphoto.php?g...me=CRW_5054.jpg[/a]

Note the last line of text before the "back" link at the bottom. For me, when using Firefox there is a jarbled mess of unreadable characters between the proper characters, and when using IE the spacing is incorrect -- either way, there is some type of character encoding issue. Regardless, if you look at the HTML for this page the caption is not the same as the string in the EXIF field. The actual contents of the UserComment EXIF field for this file are: "Lake Guntersville, Guntersville, AL"

My guess is that I need to correct this by converting the string PHP is returning in my $caption variable in the code above to Unicode, but from what character set I am not sure. My goal is to obtain a string that is [b]identical[/b] to the comment I type into the EXIF UserComment file for an image.

Any help would be appreciated!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.