Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hgc81538/99d84d021d2c1c80bd53 to your computer and use it in GitHub Desktop.
Save hgc81538/99d84d021d2c1c80bd53 to your computer and use it in GitHub Desktop.
<?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