Ejemplo n.º 1
0
  def iptc_extract(self, image_path):
    im = Image.open(image_path)
    iptc_d = IPTC.getiptcinfo(im)

    #for i in xrange(120):
      #s = iptc_d.get((2,i), "None")
      #print i, s

    if iptc_d:
      self.iptc.setdefault(image_path,{'title':iptc_d.get((2, 5), "n"),
                                  'headline':iptc_d.get((2,105), "n"),
                                  'caption':iptc_d.get((2,120), "n"),
                                  'country':iptc_d.get((2,101), "n"),
                                  'province':iptc_d.get((2,95), "n"),
                                  'city':iptc_d.get((2,90), "n"),
                                  'location':iptc_d.get((2,92), "n"),
                                  'iptc_caption':iptc_d.get((2,120), "n"),
                                  'Status-JobID':iptc_d.get((2,103), "n"),
                                  'Status-Provider':iptc_d.get((2,110), "n"),
                                  'Status-Source':iptc_d.get((2,115), "n"),
                                  'Status-Instructions':iptc_d.get((2,40), "n"),
                                  'Status-Title':iptc_d.get((2,40), "n"),
                                })
    else:
      self.iptc.setdefault(image_path,{})
Ejemplo n.º 2
0
 def save(self, *args, **kwargs):
     super(ImageModel, self).save(*args, **kwargs)
     if self.date_taken is None:
         try:
             exif_date = self.EXIF.get('EXIF DateTimeOriginal', None)
             if exif_date is not None:
                 d, t = str.split(exif_date.values)
                 year, month, day = d.split(':')
                 hour, minute, second = t.split(':')
                 self.date_taken = datetime(int(year), int(month), int(day),
                                            int(hour), int(minute), int(second))
             else:
                 try:
                     image = Image.open(self.image.path)
                     iptc_data = IptcImagePlugin.getiptcinfo(image)
                     self.date_taken = date_parser.parse(iptc_data[(2, 55)], tzinfos= None)
                 except:
                     pass
         except:
             pass
     if self.date_taken is None:
         self.date_taken = datetime.now()
     if self._get_pk_val():
         self.clear_cache()
     if self.caption == "":
         try:
             self.caption = self.EXIF.get('EXIF ImageDescription', "")
         except:
             self.caption = ""
     if self.caption == "":
         try:
             image = Image.open(self.image.path)
             iptc_data = IptcImagePlugin.getiptcinfo(image)
             self.caption = iptc_data[(2,120)]
         except KeyError:
             pass
     super(ImageModel, self).save(*args, **kwargs)
     self.pre_cache()
Ejemplo n.º 3
0
    def _getiptc(self):
        # Extract IPTC information (experimental API).
        import IptcImagePlugin

        return IptcImagePlugin.getiptcinfo(self)
Ejemplo n.º 4
0
    pyexiv_hash = hashlib.sha1(pyexiv_caption).hexdigest() 

import iptcdata
f = iptcdata.open(sys.argv[1])
for x in f.datasets:
    if 'Caption/Abstract' == x.title:
        iptcdata_caption = x.value 
        iptcdata_hash = hashlib.sha1(iptcdata_caption).hexdigest() 


import Image, TiffImagePlugin, JpegImagePlugin, IptcImagePlugin
import StringIO


im = Image.open(sys.argv[1])
info = IptcImagePlugin.getiptcinfo(im)
if info:
    # extract caption
    pil_caption = info.get((2, 120))
    pil_hash = hashlib.sha1(pil_caption).hexdigest()
    # print all available fields
    '''
    for k, v in info.items():
        print "  %s %s" % (k, repr(v))
    '''


if len(set((pyexiv_hash, iptcdata_hash, pil_hash))) > 1:
    print 'differing output for %s' % (sys.argv[1]) 
    print 'pyexiv2  says %s' % pyexiv_caption
    print 'iptcdata says %s' % iptcdata_caption
Ejemplo n.º 5
0
if 'Iptc.Application2.Caption' in image.iptcKeys():
    pyexiv_caption = image['Iptc.Application2.Caption']
    pyexiv_hash = hashlib.sha1(pyexiv_caption).hexdigest()

import iptcdata
f = iptcdata.open(sys.argv[1])
for x in f.datasets:
    if 'Caption/Abstract' == x.title:
        iptcdata_caption = x.value
        iptcdata_hash = hashlib.sha1(iptcdata_caption).hexdigest()

import Image, TiffImagePlugin, JpegImagePlugin, IptcImagePlugin
import StringIO

im = Image.open(sys.argv[1])
info = IptcImagePlugin.getiptcinfo(im)
if info:
    # extract caption
    pil_caption = info.get((2, 120))
    pil_hash = hashlib.sha1(pil_caption).hexdigest()
    # print all available fields
    '''
    for k, v in info.items():
        print "  %s %s" % (k, repr(v))
    '''

if len(set((pyexiv_hash, iptcdata_hash, pil_hash))) > 1:
    print 'differing output for %s' % (sys.argv[1])
    print 'pyexiv2  says %s' % pyexiv_caption
    print 'iptcdata says %s' % iptcdata_caption
    print 'PIL      says %s' % pil_caption
Ejemplo n.º 6
0
 def _getiptc(self):
     # Extract IPTC information (experimental API).
     import IptcImagePlugin
     return IptcImagePlugin.getiptcinfo(self)