【PHP】上传图片翻转问题

【PHP】上传图片翻转问题,第1张

手机图片上传后获取到的宽高反了,网上的说法是 *** 作系统里的文件属性功能可能已经把图片给修正过了,看到的图片是正确的,但是通过getimagesize获取到的宽高不对;这时需要用到exif扩展的exif_read_data方法获取图片头部信息

 

exif扩展安装:[https://www.cnblogs.com/lanse1993/p/13229238.html]

 

- 获取宽高信息

$orientationArr = [1 => 0, 8 => -90, 3 => 180, 6 => 90]; $imageInfo = \exif_read_data($posterImg); $orientation = empty($imageInfo[‘Orientation‘]) ? -1 : $imageInfo[‘Orientation‘]; if (! empty($orientationArr[$orientation]) && abs($orientationArr[$orientation]) == 90) { $posterImgWidth = $imageInfo[‘ExifImageLength‘]; } else { $posterImgWidth = getimagesize($posterImg)[0]; }

 

- 需要用来画图时(这里用的Imagick)

//载入图像 $this->img = new \Imagick(realpath($imgname)); // 图片是否旋转 $orientationArr = [1 => 0, 8 => -90, 3 => 180, 6 => 90]; $imageInfo = \exif_read_data(realpath($imgname)); $orientation = empty($imageInfo[‘Orientation‘]) ? -1 : $imageInfo[‘Orientation‘]; if (! empty($orientationArr[$orientation])) { $this->img->rotateImage(‘#000‘, $orientationArr[$orientation]); }

 

【PHP】上传图片翻转问题

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/1006566.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存