getpelican / pelican-plugins

Collection of plugins for the Pelican static site generator
Other
1.38k stars 846 forks source link

Howto quickly create exif.txt #546

Closed AntoineVe closed 8 years ago

AntoineVe commented 9 years ago

Maybe add in the Readme how to quickly create exif.txt : e.g. :

#!/usr/bin/bash
FILENAME=$(exiftool -common $1 | grep 'File Name' | cut -d\: -f2 |tr -d \ )
CAMERA=$(exiftool -common $1 | grep 'Camera' | cut -d\: -f2 |tr -d \ )
LENGTH=$(exiftool -common $1 | grep 'Length' | cut -d\: -f2 |tr -d \ )
APERTURE=$(exiftool -common $1 | grep 'Aperture' | cut -d\: -f2 |tr -d \ )
SPEED=$(exiftool -common $1 | grep 'Speed' | cut -d\: -f2 |tr -d \ )s
ISO=$(exiftool -common $1 | grep 'ISO' | cut -d\: -f2 |tr -d \ )
LENS=$(exiftool $1 | grep 'Lens Model' | cut -d\: -f2 |cut -d\  -f2)
echo "$FILENAME: $CAMERA + $LENS ― $LENGTH - f/$APERTURE - $SPEED - ISO $ISO"

Then someting like touch exif.txt && find ./ -type f -name '*.jpg' -exec ~/exif_extract.sh {} \; >> exif.txt

If you ask me, I'll write a more complete python script to generate the exif.txt.

justinmayer commented 9 years ago

I'm not familiar with exif.txt. What is its purpose? How would it be used?

pxquim commented 9 years ago

@justinmayer The Photos plugin uses two text files "exif.txt" and "captions.txt" to hold one-line comments for each photo. Generating those files was left as an exercise for the reader, since I do it in separate pass.

The major issue is that exiftool is written in Perl, and accessing it from Python seems like a hack. However, I could not force myself to write a complete Perl solution :-)

@AntoineVe Here is the Python script that I am using:

#!/usr/bin/python

import sys
import subprocess
import os
from PIL import Image, ExifTags
import exiftool

proc= exiftool.ExifTool("/Users/px/Programming/exiftool")
proc.start()

for path in sys.argv[1:]:
    r= proc.execute_json(
        "-EXIF:Make", "-EXIF:Model", "-EXIF:FocalLength", "-EXIF:FNumber",
        "-EXIF:ExposureTime", "-EXIF:ISO", "-EXIF:Flash", "-EXIF:ExposureCompensation",
        path)[0]
    make = r.get("EXIF:Make", "")
    model= r.get("EXIF:Model", "")
    lens = r.get("EXIF:FocalLength", 0)
    f    = r.get("EXIF:FNumber", 0)
    time = r.get("EXIF:ExposureTime", 1)
    iso  = r.get("EXIF:ISO", None)
    flash= r.get("EXIF:Flash", 0)
    expo = r.get("EXIF:ExposureCompensation", 0)
    if not model:
        continue
    mm= ""
    if lens:
        mm=(' %dmm' % (lens,))
        if model=="Canon EOS 350D DIGITAL":
            model= 'Canon EOS 350D';
            mm=('%s (%d eq)' % (mm, float(lens)*1.6))
    exif= ( (model if model.startswith(make) else make + ' ' + model) +
            ' -' + mm +
            (' f/%.1f' % (f,)).replace('.0', '') +
            ((' 1/%ds' % (1/time+0.5,)) if time < 1 else ' %ds' % (time,)) +
            (' %1.1fEV' % (expo,) if expo else '') +
            (' ISO %d' % (iso,)) if iso else '' +
            ' Flash' if (flash & 1) else '')
    try:
        print path + ": " + exif
    except:
        print path
        print exif
        raise
proc.terminate()
AntoineVe commented 9 years ago

@justinmayer sorry, I haven't said this issue is for the photo plugin.

@pxquim using exiftool module and PIL is an interessing solution, I will do some comparison because the bash script is a little bit slow.

pxquim commented 9 years ago

@AntoineVe Actually the PIL import is a leftover from a previous version of the script when I actually tried to use PIL. My conclusion at the time is that the Perl exiftool is more mature and overall easier to use.

Rewriting everything is Perl is on my TODO list, but this script is good enough for my needs at this point, even if it is a gross hack.