summaryrefslogtreecommitdiff
path: root/src/png.py
blob: 377682eb706ba03fb75bf9d75a0c09e7a5fe75bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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