summaryrefslogtreecommitdiff
path: root/libmat/pillow.py
blob: 556d58a601db4d50da51b2b4003bf3b1451b5f4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
''' Care about images with help of PIL.
This class doesn't remove metadata in the "conventional way";
it opens, then saves the image. This should remove unknown metadata.
'''

# FIXME Implement this with a decorator instead

import parser


class PillowStripper(object):
    ''' This class implements a single method, "open_and_save".
        It's a class instead of a function so it can be inherited.
    '''
    def open_and_save(self):
        ''' Open and save the image with PIL.
        This should remove a lot of unknown metadata.
        '''
        try:
            from PIL import Image
        except ImportError:
            logging.error('Unable to import PIL, image support degraded. Be careful.')

        try:
            Image.open(self.filename).save(self.filename)
        except IOError:
            logging.error('Can not save %s.' % self.filename)