diff options
| -rw-r--r-- | libmat2/images.py | 15 | ||||
| -rw-r--r-- | tests/data/dirty.gif | bin | 0 -> 1127 bytes | |||
| -rw-r--r-- | tests/test_libmat2.py | 24 |
3 files changed, 39 insertions, 0 deletions
diff --git a/libmat2/images.py b/libmat2/images.py index 153a83d..dd3be53 100644 --- a/libmat2/images.py +++ b/libmat2/images.py | |||
| @@ -42,6 +42,21 @@ class PNGParser(exiftool.ExiftoolParser): | |||
| 42 | return True | 42 | return True |
| 43 | 43 | ||
| 44 | 44 | ||
| 45 | class GIFParser(exiftool.ExiftoolParser): | ||
| 46 | mimetypes = {'image/gif'} | ||
| 47 | meta_whitelist = {'AnimationIterations', 'BackgroundColor', 'BitsPerPixel', | ||
| 48 | 'ColorResolutionDepth', 'Directory', 'Duration', | ||
| 49 | 'ExifToolVersion', 'FileAccessDate', | ||
| 50 | 'FileInodeChangeDate', 'FileModifyDate', 'FileName', | ||
| 51 | 'FilePermissions', 'FileSize', 'FileType', | ||
| 52 | 'FileTypeExtension', 'FrameCount', 'GIFVersion', | ||
| 53 | 'HasColorMap', 'ImageHeight', 'ImageSize', 'ImageWidth', | ||
| 54 | 'MIMEType', 'Megapixels', 'SourceFile',} | ||
| 55 | |||
| 56 | def remove_all(self) -> bool: | ||
| 57 | return self._lightweight_cleanup() | ||
| 58 | |||
| 59 | |||
| 45 | class GdkPixbufAbstractParser(exiftool.ExiftoolParser): | 60 | class GdkPixbufAbstractParser(exiftool.ExiftoolParser): |
| 46 | """ GdkPixbuf can handle a lot of surfaces, so we're rending images on it, | 61 | """ GdkPixbuf can handle a lot of surfaces, so we're rending images on it, |
| 47 | this has the side-effect of completely removing metadata. | 62 | this has the side-effect of completely removing metadata. |
diff --git a/tests/data/dirty.gif b/tests/data/dirty.gif new file mode 100644 index 0000000..217f909 --- /dev/null +++ b/tests/data/dirty.gif | |||
| Binary files differ | |||
diff --git a/tests/test_libmat2.py b/tests/test_libmat2.py index 9152b2f..9354286 100644 --- a/tests/test_libmat2.py +++ b/tests/test_libmat2.py | |||
| @@ -171,6 +171,12 @@ class TestGetMeta(unittest.TestCase): | |||
| 171 | meta = p.get_meta() | 171 | meta = p.get_meta() |
| 172 | self.assertEqual(meta['EncodingSettings'], 'Lavf52.103.0') | 172 | self.assertEqual(meta['EncodingSettings'], 'Lavf52.103.0') |
| 173 | 173 | ||
| 174 | def test_gif(self): | ||
| 175 | p, mimetype = parser_factory.get_parser('./tests/data/dirty.gif') | ||
| 176 | self.assertEqual(mimetype, 'image/gif') | ||
| 177 | meta = p.get_meta() | ||
| 178 | self.assertEqual(meta['Comment'], 'this is a test comment') | ||
| 179 | |||
| 174 | class TestRemovingThumbnails(unittest.TestCase): | 180 | class TestRemovingThumbnails(unittest.TestCase): |
| 175 | def test_odt(self): | 181 | def test_odt(self): |
| 176 | shutil.copy('./tests/data/revision.odt', './tests/data/clean.odt') | 182 | shutil.copy('./tests/data/revision.odt', './tests/data/clean.odt') |
| @@ -572,3 +578,21 @@ class TestCleaning(unittest.TestCase): | |||
| 572 | os.remove('./tests/data/clean.wmv') | 578 | os.remove('./tests/data/clean.wmv') |
| 573 | os.remove('./tests/data/clean.cleaned.wmv') | 579 | os.remove('./tests/data/clean.cleaned.wmv') |
| 574 | os.remove('./tests/data/clean.cleaned.cleaned.wmv') | 580 | os.remove('./tests/data/clean.cleaned.cleaned.wmv') |
| 581 | |||
| 582 | def test_gif(self): | ||
| 583 | shutil.copy('./tests/data/dirty.gif', './tests/data/clean.gif') | ||
| 584 | p = images.GIFParser('./tests/data/clean.gif') | ||
| 585 | |||
| 586 | meta = p.get_meta() | ||
| 587 | self.assertEqual(meta['Comment'], 'this is a test comment') | ||
| 588 | |||
| 589 | ret = p.remove_all() | ||
| 590 | self.assertTrue(ret) | ||
| 591 | |||
| 592 | p = images.GIFParser('./tests/data/clean.cleaned.gif') | ||
| 593 | self.assertNotIn('EncodingSettings', p.get_meta()) | ||
| 594 | self.assertTrue(p.remove_all()) | ||
| 595 | |||
| 596 | os.remove('./tests/data/clean.gif') | ||
| 597 | os.remove('./tests/data/clean.cleaned.gif') | ||
| 598 | os.remove('./tests/data/clean.cleaned.cleaned.gif') | ||
