exiftool ・ Image Magick で Exif Orientation 情報を追加・編集する
Exif Orientation 情報を追加する方法と編集する方法。
Orintation 情報の形式
Orientation は、Exif 2.3 規格において、 1〜8 の数字で規定されている。 http://www.cipa.jp/hyoujunka/kikaku/pdf/DC-008-2010_J.pdf (P.34) http://www.cipa.jp/english/hyoujunka/kikaku/pdf/DC-008-2012_E.pdf (P.35)
いろんなアプリで数字だったり、文字列だったりとバラバラなので混乱しやすい。 以下、早見表。exiftool の value の通りに動かすと、元の画像に戻る。
Exif定義 = exiftoolのvalue = Image Magickのvalue ---- 1 = Horizontal (normal) = top-left 2 = Mirror horizontal = top-right 3 = Rotate 180 = bottom-right 4 = Mirror vertical = bottom-left 5 = Mirror horizontal and rotate 270 CW = left-top 6 = Rotate 90 CW = right-top 7 = Mirror horizontal and rotate 90 CW = right-bottom 8 = Rotate 270 CW = left-bottom ※CW=Clock Work = 時計回り
Orientation 情報付与
$ exiftool -Orientation=6 -n add_orientation_img.jpg or $ exiftool -Orientation="Rotate 90 CW" add_orientation_img.jpg
exiftoolは、Orientation情報を Rotate 90 CW
のような文字列で操作するので、数字で値を入力したいときは、-n
オプションを使う。
Orientation 情報編集
$ convert input_img.jpg -orient right-top output_img.jpg
convert の orient は、Exif Orientation情報が存在していない場合に、新しく付与することはできない。編集に限定される。また、Orientation情報 を right-top
のような文字列で操作する。(早見表をみるべし)
おまけ
- Orientation情報の変更を確認する
$ identify -verbose edited_img.jpg | grep Orientation Orientation: RightTop exif:Orientation: 6
- Image Magick で Orientation 情報を使って写真を回転させる
$ convert -auto-orient -strip input_img.jpg output_img.jpg
-strip
で、余分な exif情報を消去しておくこと。
参考
exiftool exif tag list http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html
convert orient options http://www.imagemagick.org/script/command-line-options.php#orient