You are here

function ExifPHPExtension::_normalise_fraction in Exif 7

Normalise fractions.

1 call to ExifPHPExtension::_normalise_fraction()
ExifPHPExtension::_reformat in ./ExifPHPExtension.php
Helper function to reformat fields where required.

File

./ExifPHPExtension.php, line 211

Class

ExifPHPExtension

Namespace

Drupal\exif

Code

function _normalise_fraction($fraction) {
  $parts = explode('/', $fraction);
  $top = $parts[0];
  $bottom = $parts[1];
  if ($top > $bottom) {

    // Value > 1
    if ($top % $bottom == 0) {
      $value = $top / $bottom;
    }
    else {
      $value = round($top / $bottom, 2);
    }
  }
  else {
    if ($top == $bottom) {

      // Value = 1
      $value = '1';
    }
    else {

      // Value < 1
      if ($top == 1) {
        $value = '1/' . $bottom;
      }
      else {
        if ($top != 0) {
          $value = '1/' . round($bottom / $top, 0);
        }
        else {
          $value = '0';
        }
      }
    }
  }
  return $value;
}