Skip to content

Instantly share code, notes, and snippets.

@ancyrweb
Last active January 26, 2018 17:01
Show Gist options
  • Save ancyrweb/06f20da3a27053002373fa939fd9d563 to your computer and use it in GitHub Desktop.
Save ancyrweb/06f20da3a27053002373fa939fd9d563 to your computer and use it in GitHub Desktop.
<?php
/**
* See http://sylvana.net/jpegcrop/exif_orientation.html
*/
function fixOrientation(Imagick $image) {
$orientation = $image->getImageOrientation();
switch($orientation) {
case 2:
$image->flipImage();
break;
case 3:
$image->rotateimage("#FFF", 180);
break;
case 4:
$image->rotateimage("#FFF", 180);
$image->flipImage();
break;
case 5:
$image->rotateimage("#FFF", 90);
$image->flipImage();
break;
case 6:
$image->rotateimage("#FFF", 90);
break;
case 7:
$image->rotateimage("#FFF", -90);
$image->flipImage();
break;
case 8:
$image->rotateimage("#FFF", -90);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment