summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Billington <chrisjbillington@gmail.com>2019-08-03 20:56:21 +0000
committerAntónio Fernandes <antoniojpfernandes@gmail.com>2019-08-03 20:56:21 +0000
commit26d33d74f468a8ab10b4a1c3c8aa66b66205e112 (patch)
treee550729e6c25320302ec0b7e5db7a621bbc81ede
parent8a51db795342873a459c0e4031cd2782a7618776 (diff)
downloadnautilus-26d33d74f468a8ab10b4a1c3c8aa66b66205e112.tar.gz
nautilus-file.c: Add transparent padding to thumbnails
Pad thumbnails with transparency such that the resulting image is square. This ensures that the pixmap has room for emblems even when the image has an extreme aspect ratio. Closes #912
-rw-r--r--src/nautilus-file.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index 0a76d64e3..8d1fbb54c 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -5173,6 +5173,9 @@ nautilus_file_get_thumbnail_icon (NautilusFile *file,
}
else
{
+ GdkPixbuf *bg_pixbuf;
+ int bg_size;
+
pixbuf = gdk_pixbuf_scale_simple (file->details->thumbnail,
MAX (w * thumb_scale, 1),
MAX (h * thumb_scale, 1),
@@ -5198,13 +5201,32 @@ nautilus_file_get_thumbnail_icon (NautilusFile *file,
}
}
+ /* Copy to a transparent square pixbuf, aligned to the bottom edge */
+ bg_size = MAX (gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf));
+ bg_pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (pixbuf),
+ TRUE,
+ gdk_pixbuf_get_bits_per_sample (pixbuf),
+ bg_size,
+ bg_size);
+ gdk_pixbuf_fill (bg_pixbuf, 0);
+ gdk_pixbuf_copy_area (pixbuf,
+ 0,
+ 0,
+ gdk_pixbuf_get_width (pixbuf),
+ gdk_pixbuf_get_height (pixbuf),
+ bg_pixbuf,
+ (bg_size - gdk_pixbuf_get_width (pixbuf)) / 2,
+ (bg_size - gdk_pixbuf_get_height (pixbuf)));
+ g_clear_object (&pixbuf);
+ pixbuf = bg_pixbuf;
+
g_clear_object (&file->details->scaled_thumbnail);
file->details->scaled_thumbnail = pixbuf;
file->details->thumbnail_scale = thumb_scale;
}
DEBUG ("Returning thumbnailed image, at size %d %d",
- (int) (w * thumb_scale), (int) (h * thumb_scale));
+ gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf));
}
else if (file->details->thumbnail_path == NULL &&
file->details->can_read &&