1 回答
TA贡献1853条经验 获得超6个赞
我使用以下代码解决了这个问题。它将从 EXIF 数据中检测方向,并根据方向值旋转它。这是在上传图像时完成的。
move_uploaded_file($uploadedFile, $destinationFilename);
correctImageOrientation($destinationFilename);
function correctImageOrientation($filename) {
if (function_exists('exif_read_data')) {
$exif = exif_read_data($filename);
if($exif && isset($exif['Orientation'])) {
$orientation = $exif['Orientation'];
if($orientation != 1){
$img = imagecreatefromjpeg($filename);
$deg = 0;
switch ($orientation) {
case 3:
$deg = 180;
break;
case 6:
$deg = 270;
break;
case 8:
$deg = 90;
break;
}
if ($deg) {
$img = imagerotate($img, $deg, 0);
}
// then rewrite the rotated image back to the disk as $filename
imagejpeg($img, $filename, 95);
} // if there is some rotation necessary
} // if have the exif orientation info
} // if function exists
}
- 1 回答
- 0 关注
- 273 浏览
添加回答
举报