note 113944 added to function.exif-read-data
| From: | iam at thatguy dot co dot za | Date: | Fri, 20 Dec 2013 08:15:55 +0000 |
| Subject: | note 113944 added to function.exif-read-data | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-197986@lists.php.net to get a copy of this message | ||
I posted the original version of the function, but after using it for a while I discovered I
didn't do enough error checking.
I have re-factored it somewhat, and it now returns an empty array should it not be able to read the
image's exif. If it is able to, it will return the details it was able to retrieve. And this
should be without error.
I am suppressing errors, because if you pass it images which cannot parse, you will get a warning.
<?php
# Modified Version of cameraUsed, no longer returns date.
public function cameraUsed($imagePath)
{
# The default empty return
$return = array(
'make' => "",
'model' => "",
'exposure' => "",
'aperture' => "",
'iso' => ""
);
// Check if the variable is set and if the file itself exists before continuing
if ((isset($imagePath)) AND (file_exists($imagePath)))
{
// There are 2 arrays which contains the information we are after, so it's easier to
state them both
$exif_ifd0 = @read_exif_data($imagePath ,'IFD0' ,0);
$exif_exif = @read_exif_data($imagePath ,'EXIF' ,0);
# Ensure that we actually got some information
if (($exif_ifd0 !== false) AND ($exif_exif !== false))
{
// Make
if (@array_key_exists('Make', $exif_ifd0))
{
$return['make'] = $exif_ifd0['Make'];
}
// Model
if (@array_key_exists('Model', $exif_ifd0))
{
$return['model'] = $exif_ifd0['Model'];
}
// Exposure
if (@array_key_exists('ExposureTime', $exif_ifd0))
{
$return['exposure'] = $exif_ifd0['ExposureTime'];
}
// Aperture
if (@array_key_exists('ApertureFNumber', $exif_ifd0['COMPUTED']))
{
$return['aperture'] =
$exif_ifd0['COMPUTED']['ApertureFNumber'];
}
// ISO
if (@array_key_exists('ISOSpeedRatings',$exif_exif))
{
$return['iso'] = $exif_exif['ISOSpeedRatings'];
}
}
}
# Return either an empty array, or the details which we were able to extrapolate.
return $return;
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/function.exif-read-data.php
Edit -- https://master.php.net/note/edit/113944
Del: integrated -- https://master.php.net/note/delete/113944/integrated
Del: useless -- https://master.php.net/note/delete/113944/useless
Del: bad code -- https://master.php.net/note/delete/113944/bad+code
Del: spam -- https://master.php.net/note/delete/113944/spam
Del: non-english -- https://master.php.net/note/delete/113944/non-english
Del: in docs -- https://master.php.net/note/delete/113944/in+docs
Del: other reasons-- https://master.php.net/note/delete/113944
Reject -- https://master.php.net/note/reject/113944
Search -- https://master.php.net/manage/user-notes.php