Daniel Brötzmann pushed to branch master at gajim / gajim
Commits:
c1e41f53 by wurstsalat at 2022-10-09T12:02:17+02:00
cfix: Preview: Try to create GdKPixbuf loader with fixed mime-type
This fixes mime-type detection problems for HEIF images on some systems
- - - - -
2 changed files:
- gajim/common/preview.py
- gajim/common/preview_helpers.py
Changes:
=====================================
gajim/common/preview.py
=====================================
@@ -157,7 +157,7 @@ def orig_exists(self) -> bool:
return self.orig_path.exists()
def create_thumbnail(self, data: bytes) -> bool:
- self.thumbnail = create_thumbnail(data, self.size)
+ self.thumbnail = create_thumbnail(data, self.size, self.mime_type)
if self.thumbnail is None:
self.info_message = _('Creating thumbnail failed')
log.warning('Creating thumbnail failed for: %s', self.orig_path)
=====================================
gajim/common/preview_helpers.py
=====================================
@@ -147,15 +147,31 @@ def extract_and_resize_frames(image: Image.Image,
return frames, result
-def create_thumbnail(data: bytes, size: int) -> Optional[bytes]:
+def create_thumbnail(data: bytes,
+ size: int,
+ mime_type: str
+ ) -> Optional[bytes]:
+
thumbnail = create_thumbnail_with_pil(data, size)
if thumbnail is not None:
return thumbnail
- return create_thumbnail_with_pixbuf(data, size)
+ return create_thumbnail_with_pixbuf(data, size, mime_type)
-def create_thumbnail_with_pixbuf(data: bytes, size: int) -> Optional[bytes]:
- loader = GdkPixbuf.PixbufLoader()
+def create_thumbnail_with_pixbuf(data: bytes,
+ size: int,
+ mime_type: str
+ ) -> Optional[bytes]:
+
+ try:
+ # Try to create GdKPixbuf loader with fixed mime-type to
+ # fix mime-type detection for HEIF images on some systems
+ loader = GdkPixbuf.PixbufLoader.new_with_mime_type(mime_type)
+ except GLib.Error as error:
+ log.warning('Creating pixbuf loader with mime '
+ 'type %s failed: %s', mime_type, error)
+ loader = GdkPixbuf.PixbufLoader()
+
try:
loader.write(data)
loader.close()
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/c1e41f53afce030e18c0fc6cdc3dc575f65f42f7
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/c1e41f53afce030e18c0fc6cdc3dc575f65f42f7
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits