Removing EXIF ​​metadata in python

I am using Django-media-tree to import images into a site's image library. I find a bug in PIL where some unknown EXIF ​​data in the image throws an unhandled exception in the thumbnail generation. Rather than hacking the PIL, I just want to remove all EXIF ​​data from the image before processing the PIL.

Using chilkat.CkXmp () I'm trying to rewrite an image to a new directory in pure form, however the RemoveAllEmbedded () method returns None and the image is overwritten with unchanged EXIF ​​data.

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 way to clean up images, I am open to suggestions .....

TIA

+3
python exif chilkat


source to share


No one has answered this question yet

See similar questions:

eleven
Python: removing Exif information from images

or similar:

5504
Does Python have a ternary conditional operator?
5231
What are metaclasses in Python?
4473
Calling an external command in Python
3790
How can I safely create a subdirectory?
3602
Does Python have a substring method "contains"?
3119
What is the difference between Python list methods that are appended and expanded?
2818
Finding the index of an element by specifying the list that contains it in Python
2601
How can I make a time delay in Python?
2568
How to find the current time in Python
1568
How can I remove the trailing line feed?



All Articles
Loading...
X
Show
Funny
Dev
Pics