解决ios上传的图片旋转问题

#开启php配置

 function adjustPicOrientation($full_filename){
        $exif = exif_read_data($full_filename);
        if($exif && isset($exif['Orientation'])) {
            $orientation = $exif['Orientation'];
            if($orientation != 1){
                $img = imagecreatefromjpeg($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 ($mirror) $img = _mirrorImage($img);
            imagejpeg($img, $full_filename, 95);
        }
    }
    return $full_filename;
}
 function _mirrorImage ( $imgsrc)
{


    $width = imagesx ( $imgsrc );
    $height = imagesy ( $imgsrc );

    $src_x = $width -1;
    $src_y = 0;
    $src_width = -$width;
    $src_height = $height;

    $imgdest = imagecreatetruecolor ( $width, $height );

    if ( imagecopyresampled ( $imgdest, $imgsrc, 0, 0, $src_x, $src_y, $width, $height, $src_width, $src_height ) )
    {
        return $imgdest;
    }

    return $imgsrc;
}

array (size=21)
‘FileName’ => string ‘2.jpg’ (length=5)
‘FileDateTime’ => int 1513667197
‘FileSize’ => int 2704297
‘FileType’ => int 2
‘MimeType’ => string ‘image/jpeg’ (length=10)
‘SectionsFound’ => string ‘ANY_TAG, IFD0, THUMBNAIL, EXIF’ (length=30)
‘COMPUTED’ =>
array (size=7)
‘html’ => string ‘width=”4032” height=”3024”’ (length=26)
‘Height’ => int 3024
‘Width’ => int 4032
‘IsColor’ => int 1
‘ByteOrderMotorola’ => int 1
‘Thumbnail.FileType’ => int 2
‘Thumbnail.MimeType’ => string ‘image/jpeg’ (length=10)
‘Orientation’ => int 6
‘XResolution’ => string ‘72/1’ (length=4)
‘YResolution’ => string ‘72/1’ (length=4)
‘ResolutionUnit’ => int 2
‘YCbCrPositioning’ => int 1
‘Exif_IFD_Pointer’ => int 102
‘THUMBNAIL’ =>
array (size=6)
‘Compression’ => int 6
‘XResolution’ => string ‘72/1’ (length=4)
‘YResolution’ => string ‘72/1’ (length=4)
‘ResolutionUnit’ => int 2
‘JPEGInterchangeFormat’ => int 286
‘JPEGInterchangeFormatLength’ => int 12566
‘ExifVersion’ => string ‘0221’ (length=4)
‘ComponentsConfiguration’ => string ‘�’ (length=4)
‘FlashPixVersion’ => string ‘0100’ (length=4)
‘ColorSpace’ => int 1
‘ExifImageWidth’ => int 4032
‘ExifImageLength’ => int 3024
‘SceneCaptureType’ => int 0`
“`

这里写图片描述

‘Orientation’ => int 6
旋转了270

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值