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/images_pixbuf.py | |
| parent | c186fc42929b2660e5c507adeb8a8fb406593b11 (diff) | |
Add support for .tiff files
Diffstat (limited to 'src/images_pixbuf.py')
| -rw-r--r-- | src/images_pixbuf.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/images_pixbuf.py b/src/images_pixbuf.py new file mode 100644 index 0000000..8eeffbe --- /dev/null +++ b/src/images_pixbuf.py | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | import subprocess | ||
| 2 | import json | ||
| 3 | import os | ||
| 4 | |||
| 5 | import gi | ||
| 6 | gi.require_version('GdkPixbuf', '2.0') | ||
| 7 | from gi.repository import GdkPixbuf | ||
| 8 | |||
| 9 | from . import abstract | ||
| 10 | |||
| 11 | class GdkPixbufAbstractParser(abstract.AbstractParser): | ||
| 12 | def get_meta(self): | ||
| 13 | out = subprocess.check_output(['exiftool', '-json', self.filename]) | ||
| 14 | meta = json.loads(out.decode('utf-8'))[0] | ||
| 15 | for key in self.meta_whitelist: | ||
| 16 | meta.pop(key, None) | ||
| 17 | return meta | ||
| 18 | |||
| 19 | def remove_all(self): | ||
| 20 | _, extension = os.path.splitext(self.filename) | ||
| 21 | pixbuf = GdkPixbuf.Pixbuf.new_from_file(self.filename) | ||
| 22 | if extension == '.jpg': | ||
| 23 | extension = '.jpeg' | ||
| 24 | pixbuf.savev(self.output_filename, extension[1:], ["quality"], ["100"]) | ||
| 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 | |||
