diff options
| author | jvoisin | 2018-04-01 12:30:00 +0200 |
|---|---|---|
| committer | jvoisin | 2018-04-01 12:30:00 +0200 |
| commit | 27beda354d8b78c1716e659273c180d4ddfb144b (patch) | |
| tree | 5420d509f2538f742405771d8433e81ce2984148 /src | |
| parent | 711347c87f189a4fd1bd425144934016b79f099c (diff) | |
Move every image-related parser into a single file
Diffstat (limited to 'src')
| -rw-r--r-- | src/images.py (renamed from src/images_pixbuf.py) | 23 | ||||
| -rw-r--r-- | src/png.py | 27 |
2 files changed, 23 insertions, 27 deletions
diff --git a/src/images_pixbuf.py b/src/images.py index 8eeffbe..560886a 100644 --- a/src/images_pixbuf.py +++ b/src/images.py | |||
| @@ -2,12 +2,35 @@ import subprocess | |||
| 2 | import json | 2 | import json |
| 3 | import os | 3 | import os |
| 4 | 4 | ||
| 5 | import cairo | ||
| 6 | |||
| 5 | import gi | 7 | import gi |
| 6 | gi.require_version('GdkPixbuf', '2.0') | 8 | gi.require_version('GdkPixbuf', '2.0') |
| 7 | from gi.repository import GdkPixbuf | 9 | from gi.repository import GdkPixbuf |
| 8 | 10 | ||
| 9 | from . import abstract | 11 | from . import abstract |
| 10 | 12 | ||
| 13 | class PNGParser(abstract.AbstractParser): | ||
| 14 | mimetypes = {'image/png', } | ||
| 15 | meta_whitelist = {'SourceFile', 'ExifToolVersion', 'FileName', | ||
| 16 | 'Directory', 'FileSize', 'FileModifyDate', 'FileAccessDate', | ||
| 17 | "FileInodeChangeDate", 'FilePermissions', 'FileType', | ||
| 18 | 'FileTypeExtension', 'MIMEType', 'ImageWidth', 'BitDepth', 'ColorType', | ||
| 19 | 'Compression', 'Filter', 'Interlace', 'BackgroundColor', 'ImageSize', | ||
| 20 | 'Megapixels', 'ImageHeight'} | ||
| 21 | |||
| 22 | def get_meta(self): | ||
| 23 | out = subprocess.check_output(['exiftool', '-json', self.filename]) | ||
| 24 | meta = json.loads(out.decode('utf-8'))[0] | ||
| 25 | for key in self.meta_whitelist: | ||
| 26 | meta.pop(key, None) | ||
| 27 | return meta | ||
| 28 | |||
| 29 | def remove_all(self): | ||
| 30 | surface = cairo.ImageSurface.create_from_png(self.filename) | ||
| 31 | surface.write_to_png(self.output_filename) | ||
| 32 | return True | ||
| 33 | |||
| 11 | class GdkPixbufAbstractParser(abstract.AbstractParser): | 34 | class GdkPixbufAbstractParser(abstract.AbstractParser): |
| 12 | def get_meta(self): | 35 | def get_meta(self): |
| 13 | out = subprocess.check_output(['exiftool', '-json', self.filename]) | 36 | out = subprocess.check_output(['exiftool', '-json', self.filename]) |
diff --git a/src/png.py b/src/png.py deleted file mode 100644 index 377682e..0000000 --- a/src/png.py +++ /dev/null | |||
| @@ -1,27 +0,0 @@ | |||
| 1 | import subprocess | ||
| 2 | import json | ||
| 3 | |||
| 4 | import cairo | ||
| 5 | |||
| 6 | from . import abstract | ||
| 7 | |||
| 8 | class PNGParser(abstract.AbstractParser): | ||
| 9 | mimetypes = {'image/png', } | ||
| 10 | meta_whitelist = {'SourceFile', 'ExifToolVersion', 'FileName', | ||
| 11 | 'Directory', 'FileSize', 'FileModifyDate', 'FileAccessDate', | ||
| 12 | "FileInodeChangeDate", 'FilePermissions', 'FileType', | ||
| 13 | 'FileTypeExtension', 'MIMEType', 'ImageWidth', 'BitDepth', 'ColorType', | ||
| 14 | 'Compression', 'Filter', 'Interlace', 'BackgroundColor', 'ImageSize', | ||
| 15 | 'Megapixels', 'ImageHeight'} | ||
| 16 | |||
| 17 | def get_meta(self): | ||
| 18 | out = subprocess.check_output(['exiftool', '-json', self.filename]) | ||
| 19 | meta = json.loads(out.decode('utf-8'))[0] | ||
| 20 | for key in self.meta_whitelist: | ||
| 21 | meta.pop(key, None) | ||
| 22 | return meta | ||
| 23 | |||
| 24 | def remove_all(self): | ||
| 25 | surface = cairo.ImageSurface.create_from_png(self.filename) | ||
| 26 | surface.write_to_png(self.output_filename) | ||
| 27 | return True | ||
