Daniel Brötzmann pushed to branch master at gajim / gajim

Commits:

2 changed files:

Changes:

  • gajim/common/preview.py
    ... ... @@ -157,7 +157,7 @@ def orig_exists(self) -> bool:
    157 157
             return self.orig_path.exists()
    
    158 158
     
    
    159 159
         def create_thumbnail(self, data: bytes) -> bool:
    
    160
    -        self.thumbnail = create_thumbnail(data, self.size)
    
    160
    +        self.thumbnail = create_thumbnail(data, self.size, self.mime_type)
    
    161 161
             if self.thumbnail is None:
    
    162 162
                 self.info_message = _('Creating thumbnail failed')
    
    163 163
                 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,
    147 147
         return frames, result
    
    148 148
     
    
    149 149
     
    
    150
    -def create_thumbnail(data: bytes, size: int) -> Optional[bytes]:
    
    150
    +def create_thumbnail(data: bytes,
    
    151
    +                     size: int,
    
    152
    +                     mime_type: str
    
    153
    +                     ) -> Optional[bytes]:
    
    154
    +
    
    151 155
         thumbnail = create_thumbnail_with_pil(data, size)
    
    152 156
         if thumbnail is not None:
    
    153 157
             return thumbnail
    
    154
    -    return create_thumbnail_with_pixbuf(data, size)
    
    158
    +    return create_thumbnail_with_pixbuf(data, size, mime_type)
    
    155 159
     
    
    156 160
     
    
    157
    -def create_thumbnail_with_pixbuf(data: bytes, size: int) -> Optional[bytes]:
    
    158
    -    loader = GdkPixbuf.PixbufLoader()
    
    161
    +def create_thumbnail_with_pixbuf(data: bytes,
    
    162
    +                                 size: int,
    
    163
    +                                 mime_type: str
    
    164
    +                                 ) -> Optional[bytes]:
    
    165
    +
    
    166
    +    try:
    
    167
    +        # Try to create GdKPixbuf loader with fixed mime-type to
    
    168
    +        # fix mime-type detection for HEIF images on some systems
    
    169
    +        loader = GdkPixbuf.PixbufLoader.new_with_mime_type(mime_type)
    
    170
    +    except GLib.Error as error:
    
    171
    +        log.warning('Creating pixbuf loader with mime '
    
    172
    +                    'type %s failed: %s', mime_type, error)
    
    173
    +        loader = GdkPixbuf.PixbufLoader()
    
    174
    +
    
    159 175
         try:
    
    160 176
             loader.write(data)
    
    161 177
             loader.close()