Skip to content

Instantly share code, notes, and snippets.

@campezzi
Last active August 29, 2015 14:05
Show Gist options
  • Save campezzi/a5ec0ec17497df2d081d to your computer and use it in GitHub Desktop.
Save campezzi/a5ec0ec17497df2d081d to your computer and use it in GitHub Desktop.
PHPThumb - Rotate image based on orientation
// 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