diff options
| author | jvoisin | 2018-03-25 15:09:12 +0200 |
|---|---|---|
| committer | jvoisin | 2018-03-25 15:09:12 +0200 |
| commit | d4d6f31655fb578825dbf1e639f165c7ad3eb17f (patch) | |
| tree | 65a5a64e2d0cf9dab964785efb1c50ce2af5eae0 /src | |
| parent | 7ad9ff08ad52d16b05e689ef383e395b7731d594 (diff) | |
Add support for jpeg
Diffstat (limited to 'src')
| -rw-r--r-- | src/parsers/jpg.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/parsers/jpg.py b/src/parsers/jpg.py new file mode 100644 index 0000000..d1a4439 --- /dev/null +++ b/src/parsers/jpg.py | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | import subprocess | ||
| 2 | import json | ||
| 3 | |||
| 4 | import gi | ||
| 5 | gi.require_version('GdkPixbuf', '2.0') | ||
| 6 | from gi.repository import GdkPixbuf | ||
| 7 | |||
| 8 | from . import abstract | ||
| 9 | |||
| 10 | class JPGParser(abstract.AbstractParser): | ||
| 11 | mimetypes = {'image/jpg', } | ||
| 12 | meta_whitelist = {'SourceFile', 'ExifToolVersion', 'FileName', | ||
| 13 | 'Directory', 'FileSize', 'FileModifyDate', 'FileAccessDate', | ||
| 14 | "FileInodeChangeDate", 'FilePermissions', 'FileType', | ||
| 15 | 'FileTypeExtension', 'MIMEType', 'ImageWidth', | ||
| 16 | 'ImageSize', 'BitsPerSample', 'ColorComponents', 'EncodingProcess', | ||
| 17 | 'JFIFVersion', 'ResolutionUnit', 'XResolution', 'YCbCrSubSampling', | ||
| 18 | 'YResolution', 'Megapixels', 'ImageHeight'} | ||
| 19 | |||
| 20 | def get_meta(self): | ||
| 21 | out = subprocess.check_output(['exiftool', '-json', self.filename]) | ||
| 22 | meta = json.loads(out)[0] | ||
| 23 | for key in self.meta_whitelist: | ||
| 24 | meta.pop(key, None) | ||
| 25 | return meta | ||
| 26 | |||
| 27 | def remove_all(self): | ||
| 28 | pixbuf = GdkPixbuf.Pixbuf.new_from_file(self.filename) | ||
| 29 | pixbuf.savev(self.output_filename, "jpeg", ["quality"], ["100"]) | ||
| 30 | return True | ||
