Quickest way to remove shadow from screenshots?

There’s an open issue about screenshots including the window’s shadow (https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/3143).

Until this issue is solved, does by chance anyone have a solution to easily remove the shadow from the screenshots ? Right now I open the screenshots with GIMP and crop the picture to remove the shadow. Does anyone have an idea on how to automate this with a script ? Sometimes I have tens of screenshots to process, it’s quite time consuming…

Probably with ImageMagick – Command-line Tools: Convert. At first I would think with the -shave or -crop option but how much padding needs to be removed from a screenshot depends on which toolkit the screenshotted app uses. See: https://gitlab.gnome.org/GNOME/gtk/-/issues/5093

So instead I’d try with something like this:

convert infile.png -fuzz 50% -trim +repage outfile.png

That worked well for me on light style with a GTK3 app and a libadwaita app. It may need some tweaking on the -fuzz option if you use dark style or for other toolkits. It leaves the corner shadow.

Here a screenshot of a libadwaita app, where I have made the background blue so you can see the padding (as per above link, for libadwaita apps there is currently a double padding):

And here after running the above command (on the original image, not the above edited one), which removed the padding and window shadow entirely:

In a shell script you could use inotifywait to watch a certain input directory for newly saved screenshots, and have it use the above command to convert them and save to a (different) output directory where you can then find your trimmed screenshots.

1 Like

You can also remove the transparency with command:

convert infile.png -alpha off outfile.png

But that turns into this:

THANKS !

Works perfectly, even on Qt apps (tested on VirtualBox, Okular, Dolphin). Great idea concerning inotify too, I will test that.

Note :
For GTK apps, another approach is to remove the shadow altogether through ~/.config/gtk-3.0/gtk.css :

decoration {
    box-shadow: none;
    margin: 0px;
}

Works on most of the GTK3 apps (tested on Nautilus, Calculator, Firefox). Doesn’t work on some other GTK apps though, most notably GIMP (maybe because my version, 2.10, still uses GTK2 I believe).

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.