# -*- coding: iso-8859-1 -*- """ xmppic.py: an XMP Image parser. date: 2006-07-12 Roberto Zoia (roberto@zoia.org) Parses JPEG images with XMP metadata (More information about XMP can be found at http://www.adobe.com/products/xmp/). xmppic.py is a minor hack of the rdfpic.py (v1.1) plugin for PyBlosxom. (rdfpic.py was developed by Roberto De Almeida, and parses JPEG images with metadata inserted using rdfpic, http://jigsaw.w3.org/rdfpic). xmppic.py has been used to extract metadata inserted by PixVUE (http://www.pixvue.com) in more than 4000 jpeg images with good results. Usage: import xmppic if xmppic.verify_installation(): data = xmppic.parse("testimage.jpg") print data """ def verify_installation(): # Try to import libxml2 try: import libxml2 except ImportError: print "I could not find the libxml2 module." print return 0 # Is PIL installed? try: import Image # Let's check if it was patched. import JpegImagePlugin if not hasattr(JpegImagePlugin, 'COM'): print "You need to patch your Image (Python Imaging Library) module." print "Take a look at:" print print " http://groups.yahoo.com/group/python-list/message/110144" print return 0 except ImportError: print "I could not find the Image (Python Imaging Library) module." print return 0 return 1 import time import os import libxml2 import Image def purgerdf(rdf): """ Purga los caracteres marcianos del texto. A parserdf no le gustan los \x00, y es lo que está en la primera de la data de la imagen. """ rdf.replace("\x00", "") rdf0 = rdf[rdf.find('1: metadata = parserdf(rdf) for k in metadata.keys(): metadata[k] = metadata[k].replace("\n","").strip() return metadata else: return None