When we take screenshots of selected areas on Ubuntu
(using Shift+Prt Scr or Ctrl+Shift+Prt Scr) we always select a rectangular area. So, I know I could just edit the image on some software like Inkscape to create a circle with the rectangular image, but I'd like to know if there's a configuration I can change for being able to select different kinds of shapes (mainly circles) directly when I'm taking the screenshot.
Is it possible?
I put together a small script for circular screenshots, you need the following packages (though it’s adaptable for other screenshot programs and terminal emulators as well):
The script
Save it as e.g.
~/circular_screenshot.bash
and make it executable withchmod +x ~/circular_screenshot.bash
. When you run it, the script first asks you to move the mouse cursor to the center position and press Enter and then to move it to an edge position (doesn’t matter which, the script calculates the radius from the distance) and again press Enter. The screen then flickers while the screenshot is taken (I recommend usingscrot $temp_screenshot
instead, it doesn’t show this odd behaviour.) and ImageMagick’sconvert
1 is used to crop the image. The output is saved with a timestamp as the filename in your home directory, you can change this behaviour by editing theoutput
variable of the script.Example output
Call without (or better: with an invisible) terminal window
I suppose you don’t want to have a terminal blocking your screen every time you make a screenshot like that, so here’s a solution for that; Call the script as follows (assuming the script was saved as
~/circular_screenshot.bash
):This runs the script in an invisible terminal window (icon with a red “X” and a blue “T”), you just need to make sure it’s focused when you type Enter. You can assign this command to a keyboard shortcut using your desktop environment’s settings.
As ImageMagick is incredibly powerful you can adapt this script to output other shapes as well, I used
ellipse
with the same radius in both x and y direction to draw the circle above – change that to e.g.$radius,$(bc <<<"$radius*0.5")
to get an ellipse with eccentricity above 0 instead.1: I took the approach from this thread on imagemagick.org.
I've discovered some things here about screenshots. When we take screenshots on Ubuntu (mine is 16.04) we're actually using a software called
gnome-screenshot
. It's an open source software written in C and we can find its source code on GitHub in this link:Well, there's a file there called
screenshot-area-selection.c
that answers my question. It's a file with 361 lines of code so I'm not going to paste it here. But as far as I understood of this file (not much), it uses many functions that are structured around building a rectangular shape... Like in this piece of code:So, my conclusion is that it's not possible to change any configuration to take screenshots using
gnome-screenshot
because its code is not structured for that... Although it's possible to download the code, change the code myself, recompile it and then use my own personalized version ofgnome-screenshot
.Using the same idea of the accepted answer I've created another script to take hexagonal screenshots and I'm sharing it here in case it's useful for someone else.
Example output
The Script
The process is exactly the same of the accepted answer. In this case I just changed the script name:
"Save it as e.g.
~/hexagonal_screenshot.bash
and make it executable withchmod +x ~/hexagonal_screenshot.bash
. When you run it, the script first asks you to move the mouse cursor to the center position and press Enter and then to move it to an edge position (doesn’t matter which, the script calculates the radius from the distance) and again press Enter. The screen then flickers while the screenshot is taken (I recommend usingscrot $temp_screenshot
instead, it doesn’t show this odd behavior.) and ImageMagick’sconvert
is used to crop the image. The output is saved with a timestamp as the filename in your home directory, you can change this behavior by editing theoutput
variable of the script."Additional Information
In case someone is curious about the math involved, here is how I did it. For creating a polygon with a different number of edges or different shapes using
Imagemagick
the procedure would be the same: do the math and add or remove points to this part of the code"polygon $P1_x,$P1_y $P2_x,$P2_y $P3_x,$P3_y $P4_x,$P4_y $P5_x,$P5_y $P6_x,$P6_y"
.