Jump to content

Validating Exif Data


foucquet

Recommended Posts

OK, so one of my cameras includes a "Copyright" field in the array returned from the exif data and one doesn't. Does anyone have any ideas how one would test for this field, and if it doesn't exist fill the relevant variable with the copyright info. I have been trying to solve this for a couple of hours now without a great deal of success, what I have is:-

$exif = exif_read_data('thistle.jpg', 'EXIF');

$name = $exif['FileName'];
$height = $exif['ExifImageWidth'];
$width = $exif['ExifImageLength'];
$copy = $exif['Copyright'];
$model = $exif['Model'];
$exposuretime = $exif['ExposureTime'];
$fnumber = $exif['COMPUTED']['ApertureFNumber'];
$iso = $exif['ISOSpeedRatings'];
$date = $exif['DateTime'];

echo "File Name: $name<br />";
echo "Comment: " . $exif['COMMENT'][0] . "<br />";
echo "Height: $height<br />";
echo "Width: $width<br />";
echo "Copyright: $copy<br />";
echo "Camera: $model<br />";
echo "Shutter Speed: $exposuretime<br />";
echo "F number: $fnumber<br />";
echo "ISO: " . $iso . "<br />";
echo "Date & Time: $date<br /><br />";

 

Whatever I try always seems to end with "Notice: Undefined index: Copyright in C:\wamp\www\php\exif-read.php on line 11" it is obviously

$copy = $exif['Copyright'];

that is causing the problem, and I can't work out just how to test for the existence of "Copyright" and head this problem off...

Link to comment
Share on other sites

There is a better way of doing the above:-

 

<?php

//>>> Set up the array for the meta data.
$exifdata = array('caption', 'copy', 'camera', 'shutter', 'fNo', 'iso', 'date', 'time');

//>>> Read the EXIF data from the image.
$exif = exif_read_data('image.jpg', 'EXIF');

/*
Test for the existence of the "Copyright" key in the $exif array and update
the "copy" key of the $exifdata array accordingly.
*/

if (array_key_exists('Copyright', $exif)) {
    echo "The 'Copyright' element is in the array, and has the value " . $exif['Copyright'];
    $exifdata['copy'] = $exif['Copyright'];
}
else {
  $exifdata['copy'] = "Copyright info";
  echo "This image is the copyright of " . $exifdata['copy'] . " and may not be used without prior permission.";
}

?>

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.