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
https://forums.phpfreaks.com/topic/249726-validating-exif-data/
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.";
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.