3

I am using Django-media-tree to import images into a site image library. I am hitting a bug in PIL where some unknown EXIF data on the image is causing a non-handled exception in the generation of the thumbnail images. Rather than hacking around in PIL I am looking to simply remove all EXIF data from the image before it is handled by PIL.

Using chilkat.CkXmp() I am attempting to rewrite the image to a new directory in clean form, however the RemoveAllEmbedded() method returns None, and the image is rewritten with the EXIF data intact.

import os
import sys
import chilkat

ALLOWED_EXTENSIONS = ['.jpg', 'jpeg', '.png', '.gif', 'tiff']

def listdir_fullpath(d):
    list = []
    for f in os.listdir(d):
        if len(f) > 3:
            if f[-4:] in ALLOWED_EXTENSIONS:
                list.append(os.path.join(d, f))
    return list

def trim_xmp_data(file, dir):
    xmp = chilkat.CkXmp()
    success = xmp.UnlockComponent("Anything for 30-day trial.")
    if (success != True):
        print xmp.lastErrorText()
        sys.exit()

    success = xmp.LoadAppFile(file)
    if (success != True):
        print xmp.lastErrorText()
        sys.exit()
    print "Num embedded XMP docs: %d" % xmp.get_NumEmbedded()

    xmp.RemoveAllEmbedded()

    #  Save the JPG.
    fn = "%s/amended/%s" % (dir, file.rsplit('/')[-1])
    success = xmp.SaveAppFile(fn)
    if (success != True):
        print xmp.lastErrorText()
        sys.exit()


for item in listdir_fullpath('/Users/harrin2/Desktop/tmp/'):
    trim_xmp_data(item, '/Users/harrin2/Desktop/tmp')

Can anyone tell me where I am going wrong, or if there is a better method of cleaning the images I am open to suggestions.....

TIA

harrin2
  • 31
  • 3
  • There is an [answer for this question](http://stackoverflow.com/questions/19786301/python-remove-exif-info-from-images) – karlcow Dec 30 '14 at 19:13

0 Answers0