This question already has an answer here:

I am looking for a tool that runs via command line.

sort of like


it simply needs to allow me to draw a rectangle on the screen.

and tell me the measurements of it.

I have tested out: "import" module by "imagemagick"..

but perhaps there is something much lighter out there ?

( or perhaps even something that I can compile myself )

marked as duplicate by Jeff Schaller, roaima, GAD3R, jordanm, meuh Mar 1 '17 at 16:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Well, xdotool getmouselocation will get you yx-coordinates. You could do this for two diagonally located vertices of your rectangle and then do the maths. The rectangle will not be visible, though. – Fiximan Mar 1 '17 at 13:18
  • @Fiximan, so nothing like what I am asking for has been invented to be used as commonly as xdotool and xprop.. etc ? – user218529 Mar 1 '17 at 13:21
  • I made the assumption such tool must already exist due to how essential it would be. – user218529 Mar 1 '17 at 13:24
  • It could exist, I just don't know of any tool. Maybe you could go more into detail, what you need this for in order to avoid the X->Y problem. Does it need to be visible or could xdotool do the job? – Fiximan Mar 1 '17 at 13:30
  • What does "lighter" mean? Wasn't there a question & answer on this already? – Jeff Schaller Mar 1 '17 at 13:31

Some workaround. You'll need gnome-screenshot and imagemagick packages as well as a few standard commands.

We'll simply define a random file name (in the temporary directory /tmp), take a screenshot and write it to said name, then analyse the image's dimensions (picking the pixel size only) and finally remove the image.

imed=$(mktemp -u).png &&\

#-a allows area specification and
#-f defines the screenshot file's location and name
gnome-screenshot -a -f "$imed" &>/dev/null &&\

#now draw the rectangle

#extract pixel dimensions form file
identify "$imed" | awk -F' ' '{print $3}' &&\

#and remove it
rm -f "$imed"

Obviously this means creating a dummy file. One might specify a tmpfs for the image's location to have it in RAM only - speeds the process up and is better for the HD's health.