mathematical error or??
Posted: Sun Feb 12, 2006 3:57 am
hey guys... new here, looking for a bit of PHP help...
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:
And the function is:
And the odd thing is the page errors out with this error:
Line 419 that it references is:
Now what's odd is that it sometimes errors for other measurements, which is the "special cases" comment. It OFTEN works fine, so I know the calculation is correct, every so often it just errors like this. It depends on the camera and I guess however the camera calculates that number (the long decimal one).
Anyone provide some help as to why it completely errors out at that *10 part?? Thanks...
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...