Last active
August 29, 2015 14:16
-
-
Save jhesyong/811dc605888d8f743e3b to your computer and use it in GitHub Desktop.
Rotate jpg according to exif
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 | |
function rotate_jpg($filename) | |
{ | |
if (exif_imagetype($filename) == IMAGETYPE_JPEG) | |
{ | |
$image = imagecreatefromjpeg($filename); | |
$image = imagerotate($image, array_values([0, 0, 0, 180, 0, 0, -90, 0, 90])[@exif_read_data($filename)['Orientation'] ?: 0], 0); | |
imagejpeg($image, $filename, 100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment