碼迷,mamicode.com
首頁 > Web開發 > 詳細

【PHP】上傳圖片翻轉問題

時間:2021-07-28 21:37:41      閱讀:0      評論:0      收藏:0      [點我收藏+]

標簽:上傳圖片   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]);
}

 

【PHP】上傳圖片翻轉問題

標簽:上傳圖片   idt   功能   方法   size   amp   div   ges   gic   

原文地址:https://www.cnblogs.com/lanse1993/p/15071589.html

(0)
(0)
   
舉報
評論 一句話評論(0
登錄后才能評論!
? 2014 mamicode.com 版權所有  聯系我們:gaon5@hotmail.com
迷上了代碼!
4399在线看MV_久久99精品久久久久久久久久_成人又黄又爽又刺激视频_能收黄台的app不收费