From 433609f8eadc05ec6aceeb2b71951cc6db318d81 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 3 Feb 2019 21:01:58 +0100 Subject: [PATCH] Implement .gif support --- libmat2/images.py | 15 +++++++++++++++ tests/data/dirty.gif | Bin 0 -> 1127 bytes tests/test_libmat2.py | 24 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 tests/data/dirty.gif 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): return True +class GIFParser(exiftool.ExiftoolParser): + mimetypes = {'image/gif'} + meta_whitelist = {'AnimationIterations', 'BackgroundColor', 'BitsPerPixel', + 'ColorResolutionDepth', 'Directory', 'Duration', + 'ExifToolVersion', 'FileAccessDate', + 'FileInodeChangeDate', 'FileModifyDate', 'FileName', + 'FilePermissions', 'FileSize', 'FileType', + 'FileTypeExtension', 'FrameCount', 'GIFVersion', + 'HasColorMap', 'ImageHeight', 'ImageSize', 'ImageWidth', + 'MIMEType', 'Megapixels', 'SourceFile',} + + def remove_all(self) -> bool: + return self._lightweight_cleanup() + + class GdkPixbufAbstractParser(exiftool.ExiftoolParser): """ GdkPixbuf can handle a lot of surfaces, so we're rending images on it, 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 0000000000000000000000000000000000000000..217f90998b05386a0a709727d72c5acc018de928 GIT binary patch literal 1127 zcmZ?wbhEHbG-5Df_{75S|NqSYAdvQ-0R<@j=k{|A33hf2a5d61U}gkLD*j|);bQpD zp!iR$BqOs}0f-V6N>YnU6q56Eb5rw57<52JfDC3}s_p4tdHOB?;yGJxb#K16=Qn@b zBadm%I+wjVwe21E@lQV24+`-A+Q+QLFT=p%94uhr!&R_Ic>)LPi&^L5N>2U>S?l%k z%I2q~8{_>d%D+xCP1h62$a}r$;EtN?{nqBc3ik0IXRr8TzN0NMBAkO`TE&TJ5=kCM zJu1_$d<#wu1iO`$i-DCvhm}E)L7733fq^++V%Hs8y;GK}_8MnXZi`wpts3k@7 zUTQI2eO|^Cz#U*#TsFUX_vy1@%xv0wqYR6-@D$p+3tPt6EmPv!w)k#RPuy!$9l2`L zCmI#E4lQH4ZN5iS|Lm(E;kxthfB$c2lxJyaZENpnlkDv2Ws&3rg%{8bEFd@VFeovo z0o{-Vc7qql4eL+u>;t-?DobA{+^-J;#DGrs@6vUHDTsQ%v0jR$9Jukl-d`~8nSAUC{cX>4k4Y0+%$ z=nzJ-o{NEvK^7D@%sD{oFB=?kTs`$hR`1P!F>HNPJen?5`n`I!^$GX!Q*YSJdY`{I zSKlqqTCnmj15?V$6W(gm_sInPy5n}_0ndf|T!c@2$1 zFpGhakFYoc=<|ODr#x5hozZuv?f(PTzQ-=}o;I(We`?*i-$tAETq$n2{rk@5UGqPP z%P=_|W^~x_MWo(mneon?ym`A{d{kS*wT^3{nOO;^VmhZE%i|p=KG)`GXl!Z}Yi?^0 zM6w(a?AdV3EwXLPq!TpKk|M*>s@$@qH|233-ROMz{#zrfbzip12dK%kv8->{$l{?j zoykFDX9VAp8-9frQ?ur~<$U4ZHtBTO?8aKx6%X84EDhTU!O&Iy;f= zN2I!9g#E8=x5*@ERCQ&{y0voAwO4I#Ux$6-Y6!07V$d%UoV(JU#jZsyp1<6st;1&7 zVacF>J-k{RRfqMqY*w3LDm!`evxydOQ#ahsD?8`Ie0+;|jhhG8o?k%E1MTN#>FDh0 P?&%WjoiLFF=niWDykz7r literal 0 HcmV?d00001 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): meta = p.get_meta() self.assertEqual(meta['EncodingSettings'], 'Lavf52.103.0') + def test_gif(self): + p, mimetype = parser_factory.get_parser('./tests/data/dirty.gif') + self.assertEqual(mimetype, 'image/gif') + meta = p.get_meta() + self.assertEqual(meta['Comment'], 'this is a test comment') + class TestRemovingThumbnails(unittest.TestCase): def test_odt(self): shutil.copy('./tests/data/revision.odt', './tests/data/clean.odt') @@ -572,3 +578,21 @@ class TestCleaning(unittest.TestCase): os.remove('./tests/data/clean.wmv') os.remove('./tests/data/clean.cleaned.wmv') os.remove('./tests/data/clean.cleaned.cleaned.wmv') + + def test_gif(self): + shutil.copy('./tests/data/dirty.gif', './tests/data/clean.gif') + p = images.GIFParser('./tests/data/clean.gif') + + meta = p.get_meta() + self.assertEqual(meta['Comment'], 'this is a test comment') + + ret = p.remove_all() + self.assertTrue(ret) + + p = images.GIFParser('./tests/data/clean.cleaned.gif') + self.assertNotIn('EncodingSettings', p.get_meta()) + self.assertTrue(p.remove_all()) + + os.remove('./tests/data/clean.gif') + os.remove('./tests/data/clean.cleaned.gif') + os.remove('./tests/data/clean.cleaned.cleaned.gif')