1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:47:44 +00:00

PixelPaint: Add simple "Crop Image to Content" feature

This command finds the smallest non-empty content bounding rect
by looking for the outermost non-transparent pixels in the image,
and then crops the image to that rect.

It's implemented in a pretty naive way, but it's a start. :^)
This commit is contained in:
Andreas Kling 2022-08-23 21:33:52 +02:00
parent 5ded6904d8
commit 34a09bbb54
5 changed files with 83 additions and 0 deletions

View file

@ -560,6 +560,19 @@ void MainWidget::initialize_menubar(GUI::Window& window)
editor->did_complete_action("Crop Image to Selection"sv);
}));
m_image_menu->add_action(GUI::Action::create(
"&Crop Image to Content", g_icon_bag.crop, [&](auto&) {
auto* editor = current_image_editor();
VERIFY(editor);
auto content_bounding_rect = editor->image().nonempty_content_bounding_rect();
if (!content_bounding_rect.has_value())
return;
editor->image().crop(content_bounding_rect.value());
editor->did_complete_action("Crop Image to Content"sv);
}));
m_layer_menu = window.add_menu("&Layer");
m_layer_menu->add_action(GUI::Action::create(
"New &Layer...", { Mod_Ctrl | Mod_Shift, Key_N }, g_icon_bag.new_layer, [&](auto&) {