summaryrefslogtreecommitdiff
path: root/libmat/pillow.py
diff options
context:
space:
mode:
authorjvoisin2015-02-22 10:10:50 +0100
committerjvoisin2015-02-22 10:15:34 +0100
commit79ce29a7d5e41bb3bb2499bc7eb99164c423aa1d (patch)
tree3c8515874cfb9e0469bf0ea32d18b2fee1a66047 /libmat/pillow.py
parent655dda11a1eaf740573f019c3e734ef202db2345 (diff)
Preliminary implementation of PIL for images.
PIL (Python Image Library) is used to open, then save images, in order to remove unknown metadata.
Diffstat (limited to 'libmat/pillow.py')
-rw-r--r--libmat/pillow.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/libmat/pillow.py b/libmat/pillow.py
new file mode 100644
index 0000000..556d58a
--- /dev/null
+++ b/libmat/pillow.py
@@ -0,0 +1,27 @@
1''' Care about images with help of PIL.
2This class doesn't remove metadata in the "conventional way";
3it opens, then saves the image. This should remove unknown metadata.
4'''
5
6# FIXME Implement this with a decorator instead
7
8import parser
9
10
11class PillowStripper(object):
12 ''' This class implements a single method, "open_and_save".
13 It's a class instead of a function so it can be inherited.
14 '''
15 def open_and_save(self):
16 ''' Open and save the image with PIL.
17 This should remove a lot of unknown metadata.
18 '''
19 try:
20 from PIL import Image
21 except ImportError:
22 logging.error('Unable to import PIL, image support degraded. Be careful.')
23
24 try:
25 Image.open(self.filename).save(self.filename)
26 except IOError:
27 logging.error('Can not save %s.' % self.filename)