cleanup readEXIF

This commit is contained in:
Piotr KUCHARSKI 2014-11-27 16:51:58 +01:00
parent 493eea95ab
commit f890b15bcc

View file

@ -91,42 +91,54 @@ function getfirstImage($dirname)
return $imageName; return $imageName;
} }
function parse_fraction($v, $round=0)
{
list($x, $y) = array_map('intval', explode('/', $v));
if (empty($x) || empty($y)) {
return $v;
}
if ($x % $y == 0) {
return $x/$y;
}
if ($y % $x == 0) {
return "1/" . $y/$x;
}
return round($x/$y, $round);
}
function readEXIF($file) function readEXIF($file)
{ {
$exif_data = ""; $exif_arr = array();
$exif_idf0 = exif_read_data($file, 'IFD0', 0); $exif_data = exif_read_data($file);
$emodel = $exif_idf0['Model'];
$efocal = $exif_idf0['FocalLength']; $exif_val = $exif_data['Model'];
//Next is only cosmectic need but give an error due to division by zero if (!empty($exif_val)) {
//list($x, $y) = preg_split('/', $efocal); $exif_arr[] = $exif_val;
//$efocal = round($x/$y, 0); }
$exif_exif = exif_read_data($file, 'EXIF', 0); $exif_val = $exif_data['FocalLength'];
$eexposuretime = $exif_exif['ExposureTime']; if (!empty($exif_val)) {
$exif_arr[] = parse_fraction($exif_val) . "mm";
}
$efnumber = $exif_exif['FNumber']; $exif_val = $exif_data['ExposureTime'];
//Next is only cosmectic need but give an error due to division by zero if (!empty($exif_val)) {
//list($x, $y) = preg_split('/', $efnumber); $exif_arr[] = parse_fraction($exif_val, 2) . "s";
//$efnumber = round($x/$y, 0); }
$eiso = $exif_exif['ISOSpeedRatings']; $exif_val = $exif_data['FNumber'];
if (!empty($exif_val)) {
$exif_arr[] = "f" . parse_fraction($exif_val);
}
$exif_date = exif_read_data($file, 'IFD0', 0); $exif_val = $exif_data['ISOSpeedRatings'];
$edate = $exif_date['DateTime']; if (!empty($exif_val)) {
if (strlen($emodel . $efocal . $eexposuretime . $efnumber . $eiso) > 0) $exif_arr[] = "ISO " . $exif_val;
$exif_data .= "::"; }
if (strlen($emodel) > 0)
$exif_data .= "$emodel"; if (count($exif_arr) > 0) {
if ($efocal > 0) return "::" . implode(" | ", $exif_arr);
$exif_data .= " | $efocal" . "mm"; }
if (strlen($eexposuretime) > 0)
$exif_data .= " | $eexposuretime" . "s";
if ($efnumber > 0)
$exif_data .= " | f$efnumber";
if (strlen($eiso) > 0)
$exif_data .= " | ISO $eiso";
return $exif_data;
} }
function checkpermissions($file) function checkpermissions($file)