diff options
| author | jvoisin | 2018-04-01 00:43:36 +0200 |
|---|---|---|
| committer | jvoisin | 2018-04-01 00:43:36 +0200 |
| commit | 2d7c703c52cae50034fc9618c72552365f7cc741 (patch) | |
| tree | c6fcd139ea0ea5d6970f8a5bb53b1bf719f222e4 /src | |
| parent | c186fc42929b2660e5c507adeb8a8fb406593b11 (diff) | |
Add support for .tiff files
Diffstat (limited to 'src')
| -rw-r--r-- | src/images_pixbuf.py (renamed from src/jpg.py) | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/src/jpg.py b/src/images_pixbuf.py index 34fc04c..8eeffbe 100644 --- a/src/jpg.py +++ b/src/images_pixbuf.py | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | import subprocess | 1 | import subprocess |
| 2 | import json | 2 | import json |
| 3 | import os | ||
| 3 | 4 | ||
| 4 | import gi | 5 | import gi |
| 5 | gi.require_version('GdkPixbuf', '2.0') | 6 | gi.require_version('GdkPixbuf', '2.0') |
| @@ -7,16 +8,7 @@ from gi.repository import GdkPixbuf | |||
| 7 | 8 | ||
| 8 | from . import abstract | 9 | from . import abstract |
| 9 | 10 | ||
| 10 | class JPGParser(abstract.AbstractParser): | 11 | class GdkPixbufAbstractParser(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): | 12 | def get_meta(self): |
| 21 | out = subprocess.check_output(['exiftool', '-json', self.filename]) | 13 | out = subprocess.check_output(['exiftool', '-json', self.filename]) |
| 22 | meta = json.loads(out.decode('utf-8'))[0] | 14 | meta = json.loads(out.decode('utf-8'))[0] |
| @@ -25,6 +17,33 @@ class JPGParser(abstract.AbstractParser): | |||
| 25 | return meta | 17 | return meta |
| 26 | 18 | ||
| 27 | def remove_all(self): | 19 | def remove_all(self): |
| 20 | _, extension = os.path.splitext(self.filename) | ||
| 28 | pixbuf = GdkPixbuf.Pixbuf.new_from_file(self.filename) | 21 | pixbuf = GdkPixbuf.Pixbuf.new_from_file(self.filename) |
| 29 | pixbuf.savev(self.output_filename, "jpeg", ["quality"], ["100"]) | 22 | if extension == '.jpg': |
| 23 | extension = '.jpeg' | ||
| 24 | pixbuf.savev(self.output_filename, extension[1:], ["quality"], ["100"]) | ||
| 30 | return True | 25 | return True |
| 26 | |||
| 27 | |||
| 28 | class JPGParser(GdkPixbufAbstractParser): | ||
| 29 | mimetypes = {'image/jpg'} | ||
| 30 | meta_whitelist = {'SourceFile', 'ExifToolVersion', 'FileName', | ||
| 31 | 'Directory', 'FileSize', 'FileModifyDate', 'FileAccessDate', | ||
| 32 | "FileInodeChangeDate", 'FilePermissions', 'FileType', | ||
| 33 | 'FileTypeExtension', 'MIMEType', 'ImageWidth', | ||
| 34 | 'ImageSize', 'BitsPerSample', 'ColorComponents', 'EncodingProcess', | ||
| 35 | 'JFIFVersion', 'ResolutionUnit', 'XResolution', 'YCbCrSubSampling', | ||
| 36 | 'YResolution', 'Megapixels', 'ImageHeight'} | ||
| 37 | |||
| 38 | |||
| 39 | class TiffParser(GdkPixbufAbstractParser): | ||
| 40 | mimetypes = {'image/tiff'} | ||
| 41 | meta_whitelist = {'Compression', 'ExifByteOrder', 'ExtraSamples', | ||
| 42 | 'FillOrder', 'PhotometricInterpretation', 'PlanarConfiguration', | ||
| 43 | 'RowsPerStrip', 'SamplesPerPixel', 'StripByteCounts', | ||
| 44 | 'StripOffsets', 'BitsPerSample', 'Directory', 'ExifToolVersion', | ||
| 45 | 'FileAccessDate', 'FileInodeChangeDate', 'FileModifyDate', | ||
| 46 | 'FileName', 'FilePermissions', 'FileSize', 'FileType', | ||
| 47 | 'FileTypeExtension', 'ImageHeight', 'ImageSize', 'ImageWidth', | ||
| 48 | 'MIMEType', 'Megapixels', 'SourceFile'} | ||
| 49 | |||
