Last active
December 16, 2015 17:09
-
-
Save weiland/5468011 to your computer and use it in GitHub Desktop.
Fixes the image's rotation automatically.
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
/** | |
* 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