Created
September 6, 2015 16:44
-
-
Save ety001/87cc8699f7b96305194a to your computer and use it in GitHub Desktop.
照片方向调整
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 adjustPicOrientation($full_filename, $type = 'jpeg'){ | |
$exif = exif_read_data($full_filename); | |
if($exif && isset($exif['Orientation'])) { | |
$orientation = $exif['Orientation']; | |
if($orientation != 1){ | |
if($type == 'jpeg'){ | |
$img = imagecreatefromjpeg($full_filename); | |
} else if($type == 'png') { | |
$img = imagecreatefrompng($full_filename); | |
} | |
$mirror = false; | |
$deg = 0; | |
switch ($orientation) { | |
case 2: | |
$mirror = true; | |
break; | |
case 3: | |
$deg = 180; | |
break; | |
case 4: | |
$deg = 180; | |
$mirror = true; | |
break; | |
case 5: | |
$deg = 270; | |
$mirror = true; | |
break; | |
case 6: | |
$deg = 270; | |
break; | |
case 7: | |
$deg = 90; | |
$mirror = true; | |
break; | |
case 8: | |
$deg = 90; | |
break; | |
} | |
if ($deg) $img = imagerotate($img, $deg, 0); | |
if($type == 'jpeg'){ | |
imagejpeg($img, $full_filename); | |
} else if($type == 'png') { | |
imagepng($img, $full_filename); | |
} | |
imagedestroy($img); | |
} | |
} | |
return $full_filename; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment