Division Issue in YAPB

Problem PHP in Yet Another Photoblog causes “Warning: Division by zero in exifReader.inc on line 859” (the problem line is in bold):

 

case TAG_SHUTTERSPEED:
  // More complicated way of expressing exposure time, so only use
  // this value if we don’t already have it from somewhere else.
  if ($this->ImageInfo[TAG_EXPOSURETIME] == 0){
    $sp = $this->ConvertAnyFormat($ValuePtr, $Format);
    // Temporary Workaround for divizion by zero problem
      if (!empty($sp[0])) {
        $this->ImageInfo[TAG_SHUTTERSPEED] = (1/exp($sp[0]*log(2)));
      } else {
        $this->ImageInfo[TAG_SHUTTERSPEED] = 0;
      }
    }
    break;

 

Looks like YAPB is attempting to create a value if one doesn’t exist for TAG_EXPOSURETIME by inventing a new value. In my problem picture, the exposure time is 0.003 seconds which != 0. So why is the ($this->ImageInfo[TAG_EXPOSURETIME] == 0) condition evaluated as true? 

Interestingly, just prior to this is some code dealing with TAG_EXPOSURETIME which seems to be affecting this. Changing the 0.5 to 0.0005 (less than my current value removes the problem.

case TAG_EXPOSURETIME:
  // Simplest way of expressing exposure time, so I trust it most.
  // (overwrite previously computd value if there is one)
  $tmp = $this->ConvertAnyFormat($ValuePtr, $Format);
  $this->ImageInfo[‘h’][“exposureTime”] = sprintf(“%6.4f s (%d/%d)”,(double)$tmp[0],$tmp[1][0],$tmp[1][1]);
  if ($tmp[0] <= 0.5){
    $this->ImageInfo[‘h’][“exposureTime”] .= sprintf(” (1/%d)”,(int)(0.5 + 1/$tmp[0]));
  }

  break;

With this conditional, the exposure time is “0.003 s (1/400) (1/400)” without “0.003 s (1/400)”. Didn’t see a reason to have it twice, so I’ve dropped it.

Also, I figure it would be better to call ImageInfo[‘h’][“exposureTime”] instead of ImageInfo[TAG_EXPOSURETIME]. With this change, it seems to have resolved the issue for me.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.