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

你是否知道我故事中的角色?

你是否知道我故事中的角色?

那天~突然在想....... 有看我故事的人,是否會知道我寫的那些故事裡,裏頭的人事物對我有何意義?...

PageSpeed Insights

PageSpeed Insi...

終於來到了黃燈分,雖說距離綠燈還有一些挑戰,但昨晚之前我還在分的紅燈啊~

將故事輸出PDF

將故事輸出PDF

應Mandy要求,她希望可以將Innstory的故事都列印出來成冊。 所以便增加了輸出PDF功能。 ...

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