LoginSignup
2
2

More than 5 years have passed since last update.

Macのコマンドラインで画像のEXIFを取得したい場合はsipsコマンドが便利

sips -g all *.jpg

でjpg画像のEXIF一覧が得られる。これを使って画像の撮影日時にrenameするスクリプトを書いた。

# -*- coding: utf-8 -*-

import os
import sys
import commands

if __name__ == "__main__":
    pics = [pic for pic in os.listdir('.') if pic.startswith('DSCN')]
    for pic in pics:
        cmd = "sips -g all " + pic +  "  | grep creation | awk '{print $2,$3}'"
        out = commands.getoutput(cmd).split()
        dst = out[0].replace(':', '-') + ' ' + out[1].replace(':', '.') + '.jpg'
        print '{pic} ->  {dst}'.format(pic=pic, dst=dst)
        os.rename('./' + pic, './' + dst)

デジカメで取った写真を整理する時に便利。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2