summaryrefslogtreecommitdiff
path: root/libmat2/images.py
diff options
context:
space:
mode:
authorjvoisin2018-10-24 19:35:07 +0200
committerjvoisin2018-10-24 19:35:07 +0200
commitfe885babeea3779d26e797cabe4703c9a1c98a2f (patch)
treed79fdbc24175bb9e9f2f5f54389a91f18bd591da /libmat2/images.py
parent1040a594d627844f7e2a165a82a3b939a9a4f4df (diff)
Implement lightweight cleaning for jpg
Diffstat (limited to 'libmat2/images.py')
-rw-r--r--libmat2/images.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/libmat2/images.py b/libmat2/images.py
index 03cecd3..153a83d 100644
--- a/libmat2/images.py
+++ b/libmat2/images.py
@@ -6,7 +6,7 @@ import cairo
6 6
7import gi 7import gi
8gi.require_version('GdkPixbuf', '2.0') 8gi.require_version('GdkPixbuf', '2.0')
9from gi.repository import GdkPixbuf 9from gi.repository import GdkPixbuf, GLib
10 10
11from . import exiftool 11from . import exiftool
12 12
@@ -50,15 +50,21 @@ class GdkPixbufAbstractParser(exiftool.ExiftoolParser):
50 50
51 def __init__(self, filename): 51 def __init__(self, filename):
52 super().__init__(filename) 52 super().__init__(filename)
53 if imghdr.what(filename) != self._type: # better safe than sorry 53 # we can't use imghdr here because of https://bugs.python.org/issue28591
54 try:
55 GdkPixbuf.Pixbuf.new_from_file(self.filename)
56 except GLib.GError:
54 raise ValueError 57 raise ValueError
55 58
56 def remove_all(self) -> bool: 59 def remove_all(self) -> bool:
60 if self.lightweight_cleaning:
61 return self._lightweight_cleanup()
62
57 _, extension = os.path.splitext(self.filename) 63 _, extension = os.path.splitext(self.filename)
58 pixbuf = GdkPixbuf.Pixbuf.new_from_file(self.filename) 64 pixbuf = GdkPixbuf.Pixbuf.new_from_file(self.filename)
59 if extension.lower() == '.jpg': 65 if extension.lower() == '.jpg':
60 extension = '.jpeg' # gdk is picky 66 extension = '.jpeg' # gdk is picky
61 pixbuf.savev(self.output_filename, extension[1:], [], []) 67 pixbuf.savev(self.output_filename, type=extension[1:], option_keys=[], option_values=[])
62 return True 68 return True
63 69
64 70