Last active
March 9, 2017 23:04
-
-
Save mafia99/b992e0b59c0fe51fee675bb2bbd25357 to your computer and use it in GitHub Desktop.
Fixing Image Oriantation
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
$exif = exif_read_data($imagePath); | |
$img = 'pathTo/imagename';//This will be the path of the Corrected image | |
//fix the Orientation if EXIF data exist | |
if (!empty($exif['Orientation'])) { | |
$imageResource = imagecreatefromjpeg($imagePath); | |
switch ($exif['Orientation']) { | |
case 8: | |
$createdImage = imagerotate($imageResource, 90, 0); | |
break; | |
case 3: | |
$createdImage = imagerotate($imageResource, 180, 0); | |
break; | |
case 6: | |
$createdImage = imagerotate($imageResource, -90, 0); | |
break; | |
} | |
if (isset($createdImage) && imagejpeg($createdImage, $img, 90)) { | |
imagedestroy($createdImage); | |
return $imageName; | |
}else{ | |
imagejpeg($imageResource, $img, 90); | |
} | |
imagedestroy($imageResource); | |
return $imageName; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment