1

关于,

一张曝光为 1/640 的照片具有“ExposureTime”eq 的 EXIF 字段。“15625/10000000”。我不确定为什么有些照片会以可读的格式显示这个值(例如,“1/100”),但我需要将这个“15625”转换回“1/640”。如何?:)

谢谢。

4

4 回答 4

5

这是简单的数学运算:只需将分数的顶部和底部除以顶部值。

  15625 / 10000000
= (15625/15625) / (10000000/15625)
= 1 / 640

在 PHP 中,您可以这样做:

$exposure = "15625/10000000";
$parts = explode("/", $exposure);
$exposure = implode("/", array(1, $parts[1]/$parts[0]));

echo $exposure;
于 2010-06-16T00:33:35.383 回答
3

我通过一些健全性检查和特殊情况改进了 ZZ Coders 的实现。它似乎适用于我的图像,其中有几个特殊情况。如果有任何问题,请告诉我,我们会改进它。

// Exposure Time
$exif = exif_read_data($fullPath, 'IFD0', true);
$arrExposureTime = explode('/', $exif['EXIF']['ExposureTime']);
// Sanity check for zero denominator.
if ($arrExposureTime[1] == 0) {
    $ExposureTime = '<sup>1</sup>/? sec';
// In case numerator is zero.
} elseif ($arrExposureTime[0] == 0) {
    $ExposureTime = '<sup>0</sup>/' . $arrExposureTime[1] . ' sec';
// When denominator is 1, display time in whole seconds, minutes, and/or hours.
} elseif ($arrExposureTime[1] == 1) {
    // In the Seconds range.
    if ($arrExposureTime[0] < 60) {
        $ExposureTime = $arrExposureTime[0] . ' s';
    // In the Minutes range.
    } elseif (($arrExposureTime[0] >= 60) && ($arrExposureTime[0] < 3600)) {
        $ExposureTime = gmdate("i\m:s\s", $arrExposureTime[0]);
    // In the Hours range.
    } else {
        $ExposureTime = gmdate("H\h:i\m:s\s", $arrExposureTime[0]);
    }
// When inverse is evenly divisable, show reduced fractional exposure.
} elseif (($arrExposureTime[1] % $arrExposureTime[0]) == 0) {
    $ExposureTime = '<sup>1</sup>/' . $arrExposureTime[1]/$arrExposureTime[0] . ' sec';
// If the value is greater or equal to 3/10, which is the smallest standard
// exposure value that doesn't divid evenly, show it in decimal form.
} elseif (($arrExposureTime[0]/$arrExposureTime[1]) >= 3/10) { 
    $ExposureTime = round(($arrExposureTime[0]/$arrExposureTime[1]), 1) . ' sec';
// If all else fails, just display it as it was found.
} else {
    $ExposureTime = '<sup>' . $arrExposureTime[0] . '</sup>/' . $arrExposureTime[1] . ' sec';
}
于 2012-06-10T17:10:54.300 回答
0

这是我用来标准化曝光的代码,

                    if (($bottom % $top) == 0) {
                            $data = '1/'.round($bottom/$top, 0).' sec';
                    }       else {
                            if ($bottom == 1) {
                                    $data = $top.' sec';
                            } else {
                                    $data = $top.'/'.$bottom.' sec';
                            }
                    }

它可以正确处理大多数曝光,但我偶尔会看到一些奇怪的曝光。

于 2010-06-16T00:39:10.583 回答
0

您可以使用欧几里德算法找到最大公约数,这将帮助您减少分数。

于 2010-06-16T00:41:13.180 回答