標簽:上傳圖片 idt 功能 方法 size amp div ges gic
手機圖片上傳后獲取到的寬高反了,網上的說法是操作系統里的文件屬性功能可能已經把圖片給修正過了,看到的圖片是正確的,但是通過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]); }
標簽:上傳圖片 idt 功能 方法 size amp div ges gic
原文地址:https://www.cnblogs.com/lanse1993/p/15071589.html