note 107888 added to function.exif-read-data
| From: | drpain at webster dot org dot za | Date: | Tue, 13 Mar 2012 11:40:36 +0000 |
| Subject: | note 107888 added to function.exif-read-data | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186625@lists.php.net to get a copy of this message | ||
Please note that when resizing images with GD and most image processing scripts or applications you
will loose the EXIF information. What I did as a workaround is book this information into MySQL
before I re-size images.
<?php
// This function is used to determine the camera details for a specific image. It returns an array
with the parameters.
function cameraUsed($imagePath) {
// 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);
//error control
$notFound = "Unavailable";
// Make
if (@array_key_exists('Make', $exif_ifd0)) {
$camMake = $exif_ifd0['Make'];
} else { $camMake = $notFound; }
// Model
if (@array_key_exists('Model', $exif_ifd0)) {
$camModel = $exif_ifd0['Model'];
} else { $camModel = $notFound; }
// Exposure
if (@array_key_exists('ExposureTime', $exif_ifd0)) {
$camExposure = $exif_ifd0['ExposureTime'];
} else { $camExposure = $notFound; }
// Aperture
if (@array_key_exists('ApertureFNumber', $exif_ifd0['COMPUTED'])) {
$camAperture = $exif_ifd0['COMPUTED']['ApertureFNumber'];
} else { $camAperture = $notFound; }
// Date
if (@array_key_exists('DateTime', $exif_ifd0)) {
$camDate = $exif_ifd0['DateTime'];
} else { $camDate = $notFound; }
// ISO
if (@array_key_exists('ISOSpeedRatings',$exif_exif)) {
$camIso = $exif_exif['ISOSpeedRatings'];
} else { $camIso = $notFound; }
$return = array();
$return['make'] = $camMake;
$return['model'] = $camModel;
$return['exposure'] = $camExposure;
$return['aperture'] = $camAperture;
$return['date'] = $camDate;
$return['iso'] = $camIso;
return $return;
} else {
return false;
}
}
?>
An example of it's use follows:
<?php
$camera = cameraUsed("/img/myphoto.jpg");
echo "Camera Used: " . $camera['make'] . " " .
$camera['model'] . "<br />";
echo "Exposure Time: " . $camera['exposure'] . "<br />";
echo "Aperture: " . $camera['aperture'] . "<br />";
echo "ISO: " . $camera['iso'] . "<br />";
echo "Date Taken: " . $camera['date'] . "<br />";
?>
Will display the following, depending on the data:
Camera Used: SONY DSC-S930
Exposure Time: 1/400
Aperture: f/4.3
ISO: 100
Date Taken: 2010:12:10 18:18:45
If the image has been re-sized and the information is no longer available then you should receive
the following when echoing the same:
Camera Used: Unavailable
Exposure Time: Unavailable
Aperture: Unavailable
ISO: Unavailable
Date Taken: Unavailable
Some cameras do not capture all the information, for instance Blackberry phones do not record an
aperture, or iso and you will get Unavailable for those fields.
I hope you find this helpful.
----
Server IP: 195.250.77.48
Probable Submitter: 41.132.71.46
----
Manual Page -- http://www.php.net/manual/en/function.exif-read-data.php
Edit -- https://master.php.net/note/edit/107888
Del: integrated -- https://master.php.net/note/delete/107888/integrated
Del: useless -- https://master.php.net/note/delete/107888/useless
Del: bad code -- https://master.php.net/note/delete/107888/bad+code
Del: spam -- https://master.php.net/note/delete/107888/spam
Del: non-english -- https://master.php.net/note/delete/107888/non-english
Del: in docs -- https://master.php.net/note/delete/107888/in+docs
Del: other reasons-- https://master.php.net/note/delete/107888
Reject -- https://master.php.net/note/reject/107888
Search -- https://master.php.net/manage/user-notes.php