Loading...

PHP判斷手機上傳照片的方向

Temperature: 0 °C

ChungChung
author_tools

今天有點閒,所以花了點時間處理Innstory裡使用手機上傳照片變成橫向的問題。

其實這個問題存在很久了,只是一直以來都用電腦上稿所以久了就忽略了他的存在。

參考了PHP exif_read_data這篇後

需要使用exif_read_data來取得Orientation的值,之後再使用imagerotate來做轉向的動作。

如下列範例:

$exif = exif_read_data($_FILES['image_upload']['tmp_name']);//使用exif_read_data來得到上傳圖片的exif資訊陣列
if(!empty($exif['Orientation'])) {//判斷Orientation的值
switch($exif['Orientation']) {
case 8:
$image = imagerotate($image,90,0);//順時鐘翻轉90度
break;
case 3:
$image = imagerotate($image,180,0);//順時鐘翻轉180度
break;
case 6:
$image = imagerotate($image,-90,0);//逆時鐘翻轉90度
break;
}
}

測試後已經成功解決了這個轉向的問題。

稍微紀錄一下。

#故事  #PHP  #exifreaddata  
https://innstory.com/story-PHP判斷手機上傳照片的方向-2891
Innstory 寫程式筆記

Prev
 佛系水族缸

Next
曬女兒 

About the Author

Chung

我是chung
網路工作者
主業是網站系統開發建置
副業是做夢,寫故事
作品請參考/teme.biz
做夢請參考/innstory.com
聯絡/chung.teme@gmail.com

#有人用筆寫日記,有人用歲月寫日記,有人用照片寫日記,而我,用innstory寫日記。

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

將故事輸出PDF自動產生目錄

將故事輸出PDF自動產生目錄...

TCPDF輸出故事進階版本,自動產生目錄。 做了封面、做了故事內容排版,當然少不了要有目錄頁。 稍微...

我的第一本innstory notes

我的第一本innstory ...

從年月到5年月我挑了幾篇我跟Mandy的故事。 利用前陣子寫給Mandy的功能輸出了共頁內容。 終於...

將故事輸出PDF多點排版比較入眼

將故事輸出PDF多點排版比較...

知道TCPDF支援的CSS有限,Mandy也不計較排版。 但我還是過不了自己這一關。 所以趁有時間多...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format