Skip to content

Instantly share code, notes, and snippets.

@weiland
Last active December 16, 2015 17:09
Show Gist options
  • Save weiland/5468011 to your computer and use it in GitHub Desktop.
Save weiland/5468011 to your computer and use it in GitHub Desktop.
Fixes the image's rotation automatically.
/**
* Fixes the rotation
* of an image
* (with Imagick)
*/
function autoImageRotate($img) {
if(!$img) {
return false;
}
$image = new Imagick($img);
$orientation = $image->getImageOrientation();
switch($orientation) {
case 3:
$image->rotateimage("#000", 180); // 180 degrees
break;
case 6:
$image->rotateimage("#000", 90); // 90 degrees CW
break;
case 8:
$image->rotateimage("#000", -90); // 90 degrees CCW
break;
}
$image->setImageOrientation(1);
return $image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment