gthomas / iptcinfo

A Python port of Josh Carter's IPTCInfo (Perl)

Clone this repository (size: 182.2 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/gthomas/iptcinfo/
commit 2: c0d81e556423
parent 1: b48dbef461aa
branch: default
[iptcinfo @ gthomas@gthomas-laptop-20070716203426-flfv2aje4n8qxcvo] setup.py
Gulácsi Tamás
3 years ago

Changed (Δ4.9 KB):

raw changeset »

setup.py (138 lines added, 0 lines removed)

Up to file-list setup.py:

1
#!/bin/userenv python2.3
2
# -*- coding: utf-8 -*-
3
# Author: 2004 Gulácsi Tamás
4
5
u"""IPTCInfo: extract and modify IPTC (metadata) information on images - port of IPTCInfo.pm by Josh Carter <josh@multipart-mixed.com>'
6
7
Ported from Josh Carter's Perl IPTCInfo-1.9.pm by Tamás Gulácsi
8
9
Ever wish you add information to your photos like a caption, the place
10
you took it, the date, and perhaps even keywords and categories? You
11
already can. The International Press Telecommunications Council (IPTC)
12
defines a format for exchanging meta-information in news content, and
13
that includes photographs. You can embed all kinds of information in
14
your images. The trick is putting it to use.
15
16
That's where this IPTCInfo Python module comes into play. You can embed
17
information using many programs, including Adobe Photoshop, and
18
IPTCInfo will let your web server -- and other automated server
19
programs -- pull it back out. You can use the information directly in
20
Python programs, export it to XML, or even export SQL statements ready
21
to be fed into a database.
22
23
1.9.2-rc7: NOT READY
24
  IPTCInfo now accepts 'inp_charset' keyword for setting input charset.
25
26
1.9.2-rc6: just PyLint-ed out some errors.
27
28
1.9.2-rc5: Amos Latteier sent me a patch which releases the requirement of the
29
  file objects to be file objects (he uses this on jpeg files stored in
30
  databases as strings).
31
    It modifies the module in order to look for a read method on the file
32
    object. If one exists it assumes the argument is a file object, otherwise it
33
    assumes it's a filename.
34
35
1.9.2-rc4: on Windows systems, tmpfile may not work correctly - now I use
36
  cStringIO on file save (to save the file without truncating it on Exception).
37
38
1.9.2-rc3: some little bug fixes, some safety enhancements (now iptcinfo.py
39
  will overwrite the original image file (info.save()) only if everything goes
40
  fine (so if an exception is thrown at writing, it won't cut your original
41
  file).
42
43
  This is a pre-release version: needs some testing, and has an unfound bug
44
  (yet): some pictures can be enhanced with iptc data, and iptcinfo.py is able
45
  to read them, but some other iptc data readers will spit on it.
46
47
1.9.1: a first release with some little encoding support
48
49
  The class IPTCInfo now has an inp_charset and an out_charset attribute - the
50
  first is the read image's charset (defaults to the system default charset),
51
  the second is the charset the writer will use (defaults to inp_charset).
52
53
  Reader will find the charset included in IPTC data (if any, defaults to the
54
  system's default charset), and use it to read to unicode strings. Writer will
55
  write using IPTCinfo.out_charset (if it is not set, will not write charset
56
  IPTC record).
57
58
  With this, it is possible to read and write i18n strings correctly.
59
60
  I haven't tested this functionality thoroughly, and that little test was only
61
  on my WinXP box only, with the only other IPTC reader: IrfanView.
62
63
64
SYNOPSIS
65
66
  from iptcinfo import IPTCInfo
67
  import sys
68
69
  fn = (len(sys.argv) > 1 and [sys.argv[1]] or ['test.jpg'])[0]
70
  fn2 = (len(sys.argv) > 2 and [sys.argv[2]] or ['test_out.jpg'])[0]
71
72
  # Create new info object
73
  info = IPTCInfo(fn)
74
75
  # Check if file had IPTC data
76
  if len(info.data) < 4: raise Exception(info.error)
77
78
  # Print list of keywords, supplemental categories, contacts
79
  print info.keywords
80
  print info.supplementalCategories
81
  print info.contacts
82
83
  # Get specific attributes...
84
  caption = info.data['caption/abstract']
85
86
  # Create object for file that may or may not have IPTC data.
87
  info = IPTCInfo(fn)
88
89
  # Add/change an attribute
90
  info.data['caption/abstract'] = 'Witty caption here'
91
  info.data['supplemental category'] = ['portrait']
92
93
  # Save new info to file
94
  ##### See disclaimer in 'SAVING FILES' section #####
95
  info.save()
96
  info.saveAs(fn2)
97
98
  #re-read IPTC info
99
  print IPTCInfo(fn2)
100
"""
101
102
classifiers = """\
103
Development Status :: 3 - Alpha
104
License :: OSI Approved :: Artistic License
105
License :: OSI Approved :: GNU General Public License (GPL)
106
Intended Audience :: Developers
107
Programming Language :: Python
108
Topic :: Multimedia :: Graphics
109
Topic :: Utilities
110
"""
111
112
from distutils.core import setup
113
import sys
114
115
if sys.version_info < (2, 3):
116
  _setup = setup
117
  def setup(**kwargs):
118
    if kwargs.has_key("classifiers"):
119
      del kwargs["classifiers"]
120
      _setup(**kwargs)
121
122
doclines = __doc__.split("\n")
123
124
version = '1.9.2-rc6'
125
zipext = (sys.platform.startswith('Win') and ['zip'] or ['tar.gz'])[0]
126
setup(name='IPTCInfo',
127
      version=version,
128
      #url='http://www.fw.hu/gthomas/python/IPTCInfo-%s.%s' % (version, zipext),
129
      url='http://gthomas.homelinux.org/python/IPTCInfo-%s.%s' % (version, zipext),
130
      maintainer=u'Tamás Gulácsi',
131
      maintainer_email='gthomas@fw.hu',
132
      license = 'http://www.opensource.org/licenses/gpl-license.php',
133
      platforms = ['any'],
134
      description = doclines[0],
135
      classifiers = filter(None, classifiers.split('\n')),
136
      long_description = '\n'.join(doclines[2:]),
137
      py_modules=['iptcinfo'],
138
      )