1

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

sort of like

xprop
xdotool

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 )

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
  • 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. – FelixJN Mar 01 '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 ? –  Mar 01 '17 at 13:21
  • I made the assumption such tool must already exist due to how essential it would be. –  Mar 01 '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? – FelixJN Mar 01 '17 at 13:30
  • What does "lighter" mean? Wasn't there a question & answer on this already? – Jeff Schaller Mar 01 '17 at 13:31
  • @Fiximan, I am not looking to get X,Y coordinates. I only want width and height. –  Mar 01 '17 at 13:47
  • But height and width are defined by `abs(y1-y2)` and `abs(x1-x2)`, respectively. – FelixJN Mar 01 '17 at 13:55
  • @Fiximan, maybe there is already a tool in existence that turns the mouse pointer into a READY TO DRAW a shape on the screen. soon as the shape is drawn.. you get info about width and height ? –  Mar 01 '17 at 14:09
  • I'm looking exactly this. I like how the `scrot -s` works where you can draw a nice rectangle on the screen to make a print screen. I would use this supply ffmpeg arguments to capture video of the part of the screen. @user218529 did you ever find the solution? – Jaakko Dec 21 '20 at 10:49

1 Answers1

2

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.

#!/bin/bash
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.

FelixJN
  • 12,616
  • 2
  • 27
  • 48