Skip to content

Instantly share code, notes, and snippets.

@jhesyong
Last active August 29, 2015 14:16
Show Gist options
  • Save jhesyong/811dc605888d8f743e3b to your computer and use it in GitHub Desktop.
Save jhesyong/811dc605888d8f743e3b to your computer and use it in GitHub Desktop.
Rotate jpg according to exif
<?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