mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
LibGUI: Thumbnail keep the aspect ratio of the original file.
This commit is contained in:
parent
e9de8a445f
commit
f85aa8462f
Notes:
sideshowbarker
2024-07-19 07:49:28 +09:00
Author: https://github.com/sleepy-monax Commit: https://github.com/SerenityOS/serenity/commit/f85aa8462f2 Pull-request: https://github.com/SerenityOS/serenity/pull/1691
@ -470,9 +470,15 @@ static RefPtr<Gfx::Bitmap> render_thumbnail(const StringView& path)
|
||||
auto png_bitmap = Gfx::Bitmap::load_from_file(path);
|
||||
if (!png_bitmap)
|
||||
return nullptr;
|
||||
|
||||
double scale = min(32 / (double)png_bitmap->width(), 32 / (double)png_bitmap->height());
|
||||
|
||||
auto thumbnail = Gfx::Bitmap::create(png_bitmap->format(), { 32, 32 });
|
||||
Gfx::Rect destination = Gfx::Rect(0, 0, (int)(png_bitmap->width() * scale), (int)(png_bitmap->height() * scale));
|
||||
destination.center_within(thumbnail->rect());
|
||||
|
||||
Painter painter(*thumbnail);
|
||||
painter.draw_scaled_bitmap(thumbnail->rect(), *png_bitmap, png_bitmap->rect());
|
||||
painter.draw_scaled_bitmap(destination, *png_bitmap, png_bitmap->rect());
|
||||
return thumbnail;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user