foucquet Posted October 24, 2011 Share Posted October 24, 2011 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... Quote Link to comment https://forums.phpfreaks.com/topic/249726-validating-exif-data/ Share on other sites More sharing options...
foucquet Posted October 24, 2011 Author Share Posted October 24, 2011 Problem solved. I was looking for a more complex solution than it turned out to be, it was as simple as:- if(isset($exif['Copyright'])) $copy = $exif['Copyright']; else $copy = "**** ****"; Quote Link to comment https://forums.phpfreaks.com/topic/249726-validating-exif-data/#findComment-1281859 Share on other sites More sharing options...
foucquet Posted October 25, 2011 Author Share Posted October 25, 2011 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."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/249726-validating-exif-data/#findComment-1282006 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.