Skip to content

Automatically determine whether the photo has been rotated, if it is rotated, the photo is turned right

Notifications You must be signed in to change notification settings

twtrubiks/python-EXIF-Orientation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-EXIF-Orientation

自動判斷照片是否有被旋轉過,如有被旋轉,將照片轉正 📝

特色

  • 透過 JPG/JPEG 裡的 EXIF Orientation 屬性,判斷照片是否有被旋轉過。
  • 透過 pillow 將照片轉正。

安裝套件

確定電腦有安裝 Python 之後

clone 我的簡單範例

git clone https://github.com/twtrubiks/python-EXIF-Orientation.git

接著請在 cmd (命令提示字元) 輸入以下指令

pip install pillow

之前也有寫過一些 pillow 的範例,可參考我之前寫的 pillow-examples

說明

關於 JPG/JPEG 裡的 EXIF-Orientation 參數,可以參考這張圖

alt tag

從上圖可以發現

8 代表順時針轉90度

3 代表旋轉180度

6 代表逆時針90度

程式碼思路,只要先找到他們的 EXIF-Orientation 參數 (編號),也就是往哪個方向旋轉幾度,

再用 pillow 反方向旋轉回來即可。

使用方法

將要轉正的圖片放在 input_img 資料夾裡

執行

python app.py

會將轉正的圖片輸出在 output_img 資料夾裡

其他說明

這個方法只適用在 JPG/JPEG 裡,並不適用在 PNG裡面。

如果有一張圖片是從 PNG 轉成 JPG/JPEG,裡面的 EXIF-Orientation 這個參數也會消失。

執行環境

  • Python 3.4.3

Reference

License

MIT license

About

Automatically determine whether the photo has been rotated, if it is rotated, the photo is turned right

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages