summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Billington <chrisjbillington@gmail.com>2019-08-03 20:56:21 +0000
committerErnestas Kulik <ekulik@redhat.com>2019-08-06 16:16:29 +0200
commitb04f73accf15c9ebab84d85047e78756db9f2875 (patch)
treee0daf339d730c54d53a8f9ee053d8b97adbb44f2
parenta8e444a56b7b73ca44090daa161dec84d4c87f5e (diff)
downloadnautilus-b04f73accf15c9ebab84d85047e78756db9f2875.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 &&