From f391c9603c36a8ec80942c23ac6ba39fca5df72a Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 31 Mar 2018 15:46:17 +0200 Subject: Change a bit the source code organisation --- src/png.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/png.py (limited to 'src/png.py') diff --git a/src/png.py b/src/png.py new file mode 100644 index 0000000..377682e --- /dev/null +++ b/src/png.py @@ -0,0 +1,27 @@ +import subprocess +import json + +import cairo + +from . import abstract + +class PNGParser(abstract.AbstractParser): + mimetypes = {'image/png', } + meta_whitelist = {'SourceFile', 'ExifToolVersion', 'FileName', + 'Directory', 'FileSize', 'FileModifyDate', 'FileAccessDate', + "FileInodeChangeDate", 'FilePermissions', 'FileType', + 'FileTypeExtension', 'MIMEType', 'ImageWidth', 'BitDepth', 'ColorType', + 'Compression', 'Filter', 'Interlace', 'BackgroundColor', 'ImageSize', + 'Megapixels', 'ImageHeight'} + + def get_meta(self): + out = subprocess.check_output(['exiftool', '-json', self.filename]) + meta = json.loads(out.decode('utf-8'))[0] + for key in self.meta_whitelist: + meta.pop(key, None) + return meta + + def remove_all(self): + surface = cairo.ImageSurface.create_from_png(self.filename) + surface.write_to_png(self.output_filename) + return True -- cgit v1.3