Skip to content

Commit

Permalink
Tidy up code
Browse files Browse the repository at this point in the history
Refs #240
  • Loading branch information
daftspunk committed Oct 11, 2016
1 parent 97c46c5 commit 37b38ba
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions src/Database/Attach/Resizer.php
Expand Up @@ -166,34 +166,33 @@ protected function getOption($option)
*/
protected function getOrientation($file)
{

$mime = $file->getMimeType();
$filePath = $file->getPathname();

if ($mime != 'image/jpeg' || !function_exists('exif_read_data')) {
return null;
}

// lot of bad exif data
/*
* Reading the exif data is prone to fail due to bad data
*/
try {

$exif = exif_read_data($filePath);

} catch (\Exception $e) {

}
catch (Exception $e) {
return null;

}

if (!isset($exif['Orientation']))
if (!isset($exif['Orientation'])) {
return null;
}

// only take care of spin orientations, no mirrored
if (!in_array($exif['Orientation'],[1,3,6,8],true))
// Only take care of spin orientations, no mirrored
if (!in_array($exif['Orientation'], [1, 3, 6, 8], true)) {
return null;

return $exif['Orientation'];
}

return $exif['Orientation'];
}

/**
Expand All @@ -207,13 +206,11 @@ protected function getWidth()
case 6:
case 8:
return imagesy($this->image);
break;

case 1:
case 3:
default:
// includes the null case for no exif
return imagesx($this->image);
break;
}
}

Expand All @@ -228,13 +225,11 @@ protected function getHeight()
case 6:
case 8:
return imagesx($this->image);
break;

case 1:
case 3:
default:
// includes the null case for no exif
return imagesy($this->image);
break;
}
}

Expand All @@ -249,15 +244,17 @@ protected function getRotatedOriginal()
case 6:
$angle = 270.0;
break;

case 8:
$angle = 90.0;
break;

case 3:
$angle = 180.0;
break;

case 1:
default:
// includes the null case for no exif
return $this->image;
}

Expand All @@ -266,7 +263,6 @@ protected function getRotatedOriginal()

return $rotatedOriginal;
}


/**
* Resizes and/or crops an image
Expand Down

0 comments on commit 37b38ba

Please sign in to comment.