本文給大家介紹使用php技術(shù)實(shí)現(xiàn)根據(jù)上傳圖片orientation屬性判斷是否需要旋轉(zhuǎn),感興趣的朋友一起看看吧
當(dāng)使用蘋果的iOS系統(tǒng)拍照上傳圖片的時(shí)候,可能會(huì)遇到圖片被旋轉(zhuǎn)的問題,這主要是取決于你拍照時(shí)拍照按鈕的位置。假設(shè)拍照時(shí)你把手機(jī)旋轉(zhuǎn)過來底部朝上,那拍出來的照片也是被旋轉(zhuǎn)了的。
下面的代碼將確保所有上傳的照片在上傳時(shí)都能是正確定向:
- <?php
- $image = imagecreatefromstring(file_get_contents($_FILES['image_upload']['tmp_name']));
- $exif = exif_read_data($_FILES['image_upload']['tmp_name']);
- if(!emptyempty($exif['Orientation'])) {
- switch($exif['Orientation']) {
- case 8:
- $image = imagerotate($image,90,0);
- break;
- case 3:
- $image = imagerotate($image,180,0);
- break;
- case 6:
- $image = imagerotate($image,-90,0);
- break;
- }
- }
- // $image now contains a resource with the image oriented correctly
- ?>
經(jīng)測試,Android拍照的 Orientation 屬性都是1,判斷不出是否被旋轉(zhuǎn)了。
新聞熱點(diǎn)
疑難解答