You are here

private function ExifPHPExtension::normaliseFraction in Exif 8

Same name and namespace in other branches
  1. 8.2 src/ExifPHPExtension.php \Drupal\exif\ExifPHPExtension::normaliseFraction()

Normalise fractions.

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

File

src/ExifPHPExtension.php, line 747

Class

ExifPHPExtension
Class ExifPHPExtension Parser implementation base d on PHP Exif extension.

Namespace

Drupal\exif

Code

private function normaliseFraction($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;
}