Created
January 26, 2017 17:16
-
-
Save OptimusCrime/dac5deec0d65872740c9d7bccdc5e336 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <?php | |
| if(!function_exists(autoRotateImage)) { | |
| function autoRotateImage($image) { | |
| $orientation = $image->getImageOrientation(); | |
| switch($orientation) { | |
| case imagick::ORIENTATION_BOTTOMRIGHT: | |
| $image->rotateimage("#000", 180); // rotate 180 degrees | |
| break; | |
| case imagick::ORIENTATION_RIGHTTOP: | |
| $image->rotateimage("#000", 90); // rotate 90 degrees CW | |
| break; | |
| case imagick::ORIENTATION_LEFTBOTTOM: | |
| $image->rotateimage("#000", -90); // rotate 90 degrees CCW | |
| break; | |
| } | |
| // Now that it's auto-rotated, make sure the EXIF data is correct in case the EXIF gets saved with the image! | |
| $image->setImageOrientation(imagick::ORIENTATION_TOPLEFT); | |
| $image->resizeImage(800,0,Imagick::FILTER_LANCZOS,1); | |
| $cropWidth = $image->getImageWidth(); | |
| $cropHeight = $image->getImageHeight(); | |
| $newWidth = 600; | |
| $newHeight = 396; | |
| $image->cropimage( | |
| $newWidth, | |
| $newHeight, | |
| ($cropWidth - $newWidth) / 2, | |
| ($cropHeight - $newHeight) / 2 | |
| ); | |
| } | |
| } | |
| $imagen = new Imagick($photo); | |
| autoRotateImage($imagen); | |
| $imagen->writeImage($resultphoto); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment