mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 12:49:19 +00: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: f85aa8462f
Pull-request: https://github.com/SerenityOS/serenity/pull/1691
1 changed files with 7 additions and 1 deletions
|
@ -470,9 +470,15 @@ static RefPtr<Gfx::Bitmap> render_thumbnail(const StringView& path)
|
||||||
auto png_bitmap = Gfx::Bitmap::load_from_file(path);
|
auto png_bitmap = Gfx::Bitmap::load_from_file(path);
|
||||||
if (!png_bitmap)
|
if (!png_bitmap)
|
||||||
return nullptr;
|
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 });
|
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 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;
|
return thumbnail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue