diff options
| -rw-r--r-- | libmat/exiftool.py | 4 | ||||
| -rw-r--r-- | libmat/images.py | 16 | ||||
| -rw-r--r-- | libmat/pillow.py | 27 |
3 files changed, 3 insertions, 44 deletions
diff --git a/libmat/exiftool.py b/libmat/exiftool.py index 366ab12..3efd4f2 100644 --- a/libmat/exiftool.py +++ b/libmat/exiftool.py | |||
| @@ -4,10 +4,9 @@ | |||
| 4 | import subprocess | 4 | import subprocess |
| 5 | 5 | ||
| 6 | import parser | 6 | import parser |
| 7 | import pillow | ||
| 8 | 7 | ||
| 9 | 8 | ||
| 10 | class ExiftoolStripper(parser.GenericParser, pillow.PillowStripper): | 9 | class ExiftoolStripper(parser.GenericParser): |
| 11 | ''' A generic stripper class using exiftool as backend | 10 | ''' A generic stripper class using exiftool as backend |
| 12 | ''' | 11 | ''' |
| 13 | 12 | ||
| @@ -27,7 +26,6 @@ class ExiftoolStripper(parser.GenericParser, pillow.PillowStripper): | |||
| 27 | def remove_all(self): | 26 | def remove_all(self): |
| 28 | ''' Remove all metadata with help of exiftool | 27 | ''' Remove all metadata with help of exiftool |
| 29 | ''' | 28 | ''' |
| 30 | self.open_and_save() | ||
| 31 | try: | 29 | try: |
| 32 | if self.backup: | 30 | if self.backup: |
| 33 | self.create_backup_copy() | 31 | self.create_backup_copy() |
diff --git a/libmat/images.py b/libmat/images.py index 2daea88..67c710f 100644 --- a/libmat/images.py +++ b/libmat/images.py | |||
| @@ -7,21 +7,9 @@ References: | |||
| 7 | ''' | 7 | ''' |
| 8 | 8 | ||
| 9 | import parser | 9 | import parser |
| 10 | import pillow | ||
| 11 | 10 | ||
| 12 | 11 | ||
| 13 | class ImageStripper(parser.GenericParser, pillow.PillowStripper): | 12 | class JpegStripper(parser.GenericParser): |
| 14 | ''' Common stripper for images. | ||
| 15 | Its purpose is to open then save | ||
| 16 | images with PIL, the goal being to remove | ||
| 17 | unknown metadata. | ||
| 18 | ''' | ||
| 19 | def remove_all(self): | ||
| 20 | self.open_and_save() | ||
| 21 | super(ImageStripper, self).remove_all() | ||
| 22 | |||
| 23 | |||
| 24 | class JpegStripper(ImageStripper): | ||
| 25 | ''' Represents a jpeg file. | 13 | ''' Represents a jpeg file. |
| 26 | Custom Huffman and Quantization tables | 14 | Custom Huffman and Quantization tables |
| 27 | are stripped: they may leak | 15 | are stripped: they may leak |
| @@ -46,7 +34,7 @@ class JpegStripper(ImageStripper): | |||
| 46 | return True | 34 | return True |
| 47 | 35 | ||
| 48 | 36 | ||
| 49 | class PngStripper(ImageStripper): | 37 | class PngStripper(parser.GenericParser): |
| 50 | ''' Represents a png file | 38 | ''' Represents a png file |
| 51 | ''' | 39 | ''' |
| 52 | def _should_remove(self, field): | 40 | def _should_remove(self, field): |
diff --git a/libmat/pillow.py b/libmat/pillow.py deleted file mode 100644 index 5406b8b..0000000 --- a/libmat/pillow.py +++ /dev/null | |||
| @@ -1,27 +0,0 @@ | |||
| 1 | ''' Care about images with help of PIL. | ||
| 2 | This class doesn't remove metadata in the "conventional way"; | ||
| 3 | it opens, then saves the image. This should remove unknown metadata. | ||
| 4 | ''' | ||
| 5 | |||
| 6 | # FIXME Implement this with a decorator instead | ||
| 7 | |||
| 8 | import parser | ||
| 9 | |||
| 10 | |||
| 11 | class 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, exif='') | ||
| 26 | except IOError: | ||
| 27 | logging.error('Can not save %s.' % self.filename) | ||
