Codebase list gajim-urlimagepreview / 4b5373a
Imported upstream 2.1.1 W. Martin Borgert 6 years ago
3 changed file(s) with 23 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
00 [info]
11 name: Url image preview
22 short_name: url_image_preview
3 version: 2.1.0
3 version: 2.1.1
44 description: Displays a preview of links to images
55 authors = Denis Fomin <fominde@gmail.com>
66 Yann Leboulanger <asterix@lagaule.org>
7373
7474 new_frame.paste(image, (0, 0), image.convert('RGBA'))
7575
76 # This method preservs aspect ratio
7677 new_frame.thumbnail(resize_to, Image.ANTIALIAS)
7778 frames.append(new_frame)
7879
278278
279279 try:
280280 self._create_path(os.path.dirname(thumbpath))
281 height, width = pixbuf.get_height(), pixbuf.get_width()
282281 thumbnail = pixbuf
283282 if isinstance(pixbuf, GdkPixbuf.PixbufAnimation):
284 if size <= height and size <= width:
283 if size < pixbuf.get_width() or size < pixbuf.get_height():
285284 resize_gif(mem, thumbpath, (size, size))
286285 thumbnail = self._load_thumbnail(thumbpath)
287286 else:
288287 self._write_file(thumbpath, mem)
289288 else:
290 if size <= height and size <= width:
291 thumbnail = pixbuf.scale_simple(
292 size, size, GdkPixbuf.InterpType.BILINEAR)
289 width, height = self._get_thumbnail_size(pixbuf, size)
290 thumbnail = pixbuf.scale_simple(
291 width, height, GdkPixbuf.InterpType.BILINEAR)
293292 thumbnail.savev(thumbpath, 'png', [], [])
294293 except Exception as error:
295294 dialogs.ErrorDialog(
301300 log.exception(error)
302301 return
303302 return thumbnail
303
304 @staticmethod
305 def _get_thumbnail_size(pixbuf, size):
306 # Calculates the new thumbnail size while preserving the aspect ratio
307 image_width = pixbuf.get_width()
308 image_height = pixbuf.get_height()
309
310 if image_width > image_height:
311 if image_width > size:
312 image_height = int(size / float(image_width) * image_height)
313 image_width = int(size)
314 else:
315 if image_height > size:
316 image_width = int(size / float(image_height) * image_width)
317 image_height = int(size)
318
319 return image_width, image_height
304320
305321 @staticmethod
306322 def _load_thumbnail(thumbpath):