diff options
Diffstat (limited to 'printrecord.py')
-rw-r--r-- | printrecord.py | 187 |
1 files changed, 187 insertions, 0 deletions
diff --git a/printrecord.py b/printrecord.py new file mode 100644 index 0000000..65dc48a --- /dev/null +++ b/printrecord.py | |||
@@ -0,0 +1,187 @@ | |||
1 | #!/usr/bin/python | ||
2 | |||
3 | # ExiFilm -- Add film exposure metadata to EXIF tags of digital images | ||
4 | # Copyright (C) 2009 James E. Blair <corvus@gnu.org> | ||
5 | # | ||
6 | # This program is free software: you can redistribute it and/or modify | ||
7 | # it under the terms of the GNU General Public License as published by | ||
8 | # the Free Software Foundation, either version 3 of the License, or | ||
9 | # (at your option) any later version. | ||
10 | # | ||
11 | # This program is distributed in the hope that it will be useful, | ||
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | # GNU General Public License for more details. | ||
15 | # | ||
16 | # You should have received a copy of the GNU General Public License | ||
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | |||
19 | import os, sys | ||
20 | import pyexiv2 | ||
21 | import datetime | ||
22 | import decimal, fractions | ||
23 | import re | ||
24 | |||
25 | from exifilm import * | ||
26 | import lfrecord | ||
27 | |||
28 | class MyImage(object): | ||
29 | def __init__(self, fn): | ||
30 | if fn: | ||
31 | image = pyexiv2.Image(fn) | ||
32 | image.readMetadata() | ||
33 | keys = image.exifKeys() | ||
34 | self.image = image | ||
35 | else: | ||
36 | keys = [] | ||
37 | |||
38 | def get(key, default=''): | ||
39 | if key in keys: | ||
40 | return image[key] | ||
41 | return default | ||
42 | |||
43 | self.date = get('Exif.Photo.DateTimeOriginal', '') | ||
44 | |||
45 | self.shutter=from_rational(get('Exif.Photo.ExposureTime')) | ||
46 | self.aperture=to_fstop(from_rational(get('Exif.Photo.FNumber'))) | ||
47 | self.lens=from_rational(get('Exif.Photo.FocalLength')) | ||
48 | |||
49 | self.description=get('Exif.Image.ImageDescription') | ||
50 | extras, comments = decode_comments(get('Exif.Photo.UserComment')) | ||
51 | self.comments=comments | ||
52 | |||
53 | self.id = extras.get(ID, '') | ||
54 | self.film = extras.get(FILM, '') | ||
55 | self.carrier = extras.get(CARRIER, '') | ||
56 | self.process = extras.get(PROCESS, '') | ||
57 | |||
58 | self.front_movements = extras.get(FRONT_MOVEMENTS, '').split('/') | ||
59 | self.rear_movements = extras.get(REAR_MOVEMENTS, '').split('/') | ||
60 | |||
61 | def render(self): | ||
62 | r = ' (%s) (%s) (%s) (%s)\n' % (self.id, self.film, self.carrier, self.process) | ||
63 | r += ' (%s) (%s) (%s)\n' % (self.lens, self.aperture, self.shutter) | ||
64 | r += ' ' | ||
65 | |||
66 | if 'rising' in self.front_movements: r += '1 ' | ||
67 | elif 'falling' in self.front_movements: r += '-1 ' | ||
68 | else: r += '0 ' | ||
69 | |||
70 | if 'forward tilt' in self.front_movements: r += '1 ' | ||
71 | elif 'backward tilt' in self.front_movements: r += '-1 ' | ||
72 | else: r += '0 ' | ||
73 | |||
74 | if 'left swing' in self.front_movements: r += '1 ' | ||
75 | elif 'right swing' in self.front_movements: r += '-1 ' | ||
76 | else: r += '0 ' | ||
77 | |||
78 | if 'left shift' in self.front_movements: r += '1 ' | ||
79 | elif 'right shift' in self.front_movements: r += '-1 ' | ||
80 | else: r += '0 ' | ||
81 | |||
82 | r += ' ' | ||
83 | |||
84 | if 'rising' in self.rear_movements: r += '1 ' | ||
85 | elif 'falling' in self.rear_movements: r += '-1 ' | ||
86 | else: r += '0 ' | ||
87 | |||
88 | if 'forward tilt' in self.rear_movements: r += '1 ' | ||
89 | elif 'backward tilt' in self.rear_movements: r += '-1 ' | ||
90 | else: r += '0 ' | ||
91 | |||
92 | if 'left swing' in self.rear_movements: r += '1 ' | ||
93 | elif 'right swing' in self.rear_movements: r += '-1 ' | ||
94 | else: r += '0 ' | ||
95 | |||
96 | if 'left shift' in self.rear_movements: r += '1' | ||
97 | elif 'right shift' in self.rear_movements: r += '-1' | ||
98 | else: r += '0' | ||
99 | |||
100 | r += '\n' | ||
101 | |||
102 | notes = [] | ||
103 | if self.description: | ||
104 | notes.append(self.description) | ||
105 | if self.date: | ||
106 | notes.append(str(self.date.date())) | ||
107 | if self.description or self.date: | ||
108 | notes.append('') | ||
109 | notes += self.comments.split('\n') | ||
110 | |||
111 | r += ' [ ' | ||
112 | for note in notes: | ||
113 | r += '('+note+') ' | ||
114 | r += ']\n' | ||
115 | r += 'record\n' | ||
116 | return r | ||
117 | |||
118 | def main(): | ||
119 | directory = sys.argv[1] | ||
120 | start = int(sys.argv[2]) | ||
121 | end = int(sys.argv[3]) | ||
122 | end += end%4 | ||
123 | |||
124 | files = os.listdir(directory) | ||
125 | files.sort() | ||
126 | images = {} | ||
127 | for fn in files: | ||
128 | if not (fn.lower().endswith('.jpeg') or | ||
129 | fn.lower().endswith('.jpg')): | ||
130 | continue | ||
131 | i = MyImage(os.path.join(directory,fn)) | ||
132 | if i.id: | ||
133 | images[int(i.id)] = i | ||
134 | |||
135 | code = '' | ||
136 | page = 0 | ||
137 | i = start | ||
138 | while i<end: | ||
139 | page += 1 | ||
140 | code += '%%%%Page: %s %s\n' % (page, page) | ||
141 | code += '/xpos planleft def\n' | ||
142 | code += '/ypos plantop def\n' | ||
143 | |||
144 | code += 'planleft plantop\n' | ||
145 | if images.has_key(i): image = images[i] | ||
146 | else: image = MyImage(None) | ||
147 | code += image.render() | ||
148 | i += 1 | ||
149 | |||
150 | code += 'planleft planwidth add plantop\n' | ||
151 | if images.has_key(i): image = images[i] | ||
152 | else: image = MyImage(None) | ||
153 | code += image.render() | ||
154 | i += 1 | ||
155 | |||
156 | code += 'planleft plantop 5 in sub\n' | ||
157 | if images.has_key(i): image = images[i] | ||
158 | else: image = MyImage(None) | ||
159 | code += image.render() | ||
160 | i += 1 | ||
161 | |||
162 | code += 'planleft planwidth add plantop 5 in sub\n' | ||
163 | if images.has_key(i): image = images[i] | ||
164 | else: image = MyImage(None) | ||
165 | code += image.render() | ||
166 | i += 1 | ||
167 | |||
168 | code += 'showpage\n' | ||
169 | |||
170 | print lfrecord.program % dict(pages=page, code=code) | ||
171 | |||
172 | if __name__=='__main__': | ||
173 | if len(sys.argv) != 4: | ||
174 | print "Usage: %s PATH START END" % sys.argv[0] | ||
175 | |||
176 | print "Produce a sheet of four ExiFilm image records." | ||
177 | |||
178 | print " PATH is a directory with JPEG files to edit." | ||
179 | |||
180 | print " START and END are image IDs as set by ExiFilm. A series" | ||
181 | print " of PostScript pages will be generated that contain the" | ||
182 | print " images ranging from START to END." | ||
183 | |||
184 | print "Output goes to standard out." | ||
185 | else: | ||
186 | main() | ||
187 | |||