Skip to content

Instantly share code, notes, and snippets.

@mafia99
Last active March 9, 2017 23:04
Show Gist options
  • Save mafia99/b992e0b59c0fe51fee675bb2bbd25357 to your computer and use it in GitHub Desktop.
Save mafia99/b992e0b59c0fe51fee675bb2bbd25357 to your computer and use it in GitHub Desktop.
Fixing Image Oriantation
$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