Last active
August 29, 2015 14:05
-
-
Save hgc81538/99d84d021d2c1c80bd53 to your computer and use it in GitHub Desktop.
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
<?php | |
// original code is from http://stackoverflow.com/questions/7489742/php-read-exif-data-and-adjust-orientation | |
function image_fix_orientation($path){ | |
$image = imagecreatefromjpeg($path); | |
$exif = exif_read_data($path); | |
if (!empty($exif['Orientation'])) { | |
switch ($exif['Orientation']) { | |
case 3: | |
$image = imagerotate($image, 180, 0); | |
break; | |
case 6: | |
$image = imagerotate($image, -90, 0); | |
break; | |
case 8: | |
$image = imagerotate($image, 90, 0); | |
break; | |
} | |
imagejpeg($image, $path); | |
} | |
} | |
// For JPEG image only | |
image_fix_orientation('/path/to/image.jpg'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment