From 79ce29a7d5e41bb3bb2499bc7eb99164c423aa1d Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 22 Feb 2015 10:10:50 +0100 Subject: Preliminary implementation of PIL for images. PIL (Python Image Library) is used to open, then save images, in order to remove unknown metadata. --- libmat/pillow.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 libmat/pillow.py (limited to 'libmat/pillow.py') 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 @@ +''' 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) -- cgit v1.3