View Full Version : Extracting comments from a JPG

06-10-2005, 10:48 AM
Can anyone point me to some good reading material on extracting windowsXP comments from a .jpg file?

I was thinking it might be nice to be able to extract the comments from a .jpg file (right click/properties then the title. author, comments bit) but I'm having a bit of a job finding out if such a thing is even possible using php.

I'm guessing these comments are some sort of EXIF or IPTC data but most links I find seem to talk about extracting the shutterspeed and resolution type data embedded by some digital cameras.

Can someone throw me a link or two please?

Kid Charming
06-10-2005, 03:56 PM
I've never tried it, but exif_read_data() (http://us4.php.net/manual/en/function.exif-read-data.php) might by what you're looking for.

06-14-2005, 12:25 PM
Thanks Kid.

I just thought I'd report back with my findings in case anyone else was interested. Using the info on the link you gave me a fiddled around with the code a bit so that it reads and returns only the comments.

There may well be a more efficient way of doing this, at present it loops through all the headers looking for the WINMX.Comments header so any improvements welcomed :)

$exif = exif_read_data('test.jpg', 0, true);
foreach ($exif as $key => $section) {
foreach ($section as $name => $val) {
if ($key.$name = "WINXP.Comments") {
if ($val=="") {
echo "There are no comments for this file.";
else {
echo "$val";

Please not that this line if ($val=="") needs to have the one of those little square zero things in between the speach marks, like what you would see all over the screen if you opened an image file with notepad. No idea what they are called but they look like this [] sort of, Null characters?

As I said there are probably better ways of doing this but there you go :)