Extract EXIF with sips

The sips command is useful if you want to get the EXIF of an image from the Mac command line

sips -g all *.jpg

You can get the EXIF list of jpg images with. I wrote a script that uses this to rename the image when it was taken.

# -*- 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)

Useful when organizing photos taken with a digital camera.

Recommended Posts

Extract EXIF with sips
Extract non-numeric elements with pandas.DataFrame
Extract Twitter data with CSV
Extract numbers with regular expressions
Extract peak values with scipy
Extract the xz file with python
Extract the maximum value with pandas.
[Beginner] Extract character strings with Python
Extract multiple elements with Numpy array
Extract Japanese text from PDF with PDFMiner
Extract edges with OpenCV (Laplacian, Sobel, Canny)
Processed with PIL considering EXIF Orientation tag
Extract sudden buzzwords with twitter streaming API