Last active
August 29, 2015 14:05
-
-
Save campezzi/a5ec0ec17497df2d081d to your computer and use it in GitHub Desktop.
PHPThumb - Rotate image based on orientation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get PHPThumb from: https://github.com/masterexploder/PHPThumb | |
App::import('Vendor', 'PHPThumb', array('file' => 'PHPThumb/ThumbLib.inc.php')); | |
try { | |
$image = PhpThumbFactory::create($file_path, array('jpegQuality' => 75)); | |
} catch (Exception $e) { | |
$this->outputError(array('unknown_error' => 'unknown_error')); | |
} | |
$exif = @exif_read_data($file_path); | |
if (!empty($exif['Orientation'])) { | |
$orientation = $exif['Orientation']; | |
switch ($orientation) { | |
case 3: | |
$image->rotateImageNDegrees(180); | |
break; | |
case 6: | |
$image->rotateImage('CCW'); | |
break; | |
case 8: | |
$image->rotateImage('CW'); | |
break; | |
default: | |
break; | |
} | |
} | |
$image->save($file_path, 'jpg'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment