I'm putting together and working on tweaking some PHP code to have EXIF info from photos (look it up, from digi cams) be outputed via some PHP work. I already used the base code PHP EXIF Reader (found here) that works great. Only problem is, it displays some funky decimal number as the "shutter speed" instead of a nice "1/30 seconds" number. I don't exactly know what the calculation is to change it, but that isn't necessarily the concern.
My good friend wrote a small short PHP function to calculate the actual number. Anyway...
So, for reference, this photo, it outputs a number via the EXIF reading as 0.050761421319797. I used an application (non-PHP) to determine that it is actually 1/13 sec. So it needs to go from that number to 1/13.
It gets called from the original output decimal number via:
Code: Select all
$exif_data["ExposureTime"] = dTOf(round($exif_data["ExposureTime"],7));Code: Select all
function dTOf( $dec ) {
$numer=(int)$dec;
$denom=1;
// Special cases that this seems function seems to die on....
if($dec == .0333333)
return "1/30";
if($dec == .0166667)
return "1/60";
//while ($numer != $dec){ //for some reason this failed when 1/60
while($dec - $numer > .0000000001){
$dec*=10;
$denom*=10;
$numer=(int)$dec;
}
if ($denom==1)
return $numer;
$lo = $numer;
$hi = $denom;
// Euclidean Algorithm (get GCD). concepts of math proves useful :)
while($lo != 0){
$t=$hi;
$hi = $lo;
$lo = $t - floor($t / $lo) * $lo;
}
// $hi is the gcd
return ($numer / $hi) ."/". ($denom / $hi);
}Code: Select all
Fatal error: Maximum execution time of 30 seconds exceeded in /home/cmuogs/public_html/photostack/includes/exif.php on line 419Code: Select all
$dec*=10;Anyone provide some help as to why it completely errors out at that *10 part?? Thanks...