ooal_g
Last Updated: February 25, 2016
·
4.437K
· juanje

Take a screenshot from commandline

You will need to have the software ImageMagick installed in the machine you like to take screenshot from. Then you'll have the command import which takes the shots.

To take capture of the whole screen, use this:

$ import -window root /path/file.png

Then you can do some other stuff with it like resize to more suitable size:

$ import -window root -resize 600 /path/file.png

And you can do it even if you are not at the X session:

$ import -window root -resize 600 \
  -display :0 /path/file.png

So you even could take a screenshot vía ssh:

$ ssh user@host "import -window root \
  -resize 600 -display :0 png:-" > /tmp/myshot.png .

UPDATED: To simplify the ssh version, I removed the scp and redirect the output to a local file. The png:- indicates that the format is png and the the file -, which is the standard output.

7 Responses
Add your response

3007

Isn't scrot better for this.?

over 1 year ago ·
3008

@vinitcool76 Well, I'll say 'scrot' is another tool to do it (as 'xwd'), but I don't really see how is better.

I used 'import' because I have already installed 'ImageMagick' and have a lot of interesting options, but I guess I could use 'scrot' as well.

I don't see that 'scrot' have a 'display' option, so I guess I should export first the 'DISPLAY=:0' variable to be able of taking the screenshot through ssh.

over 1 year ago ·
3011

If at some point you'll decide to make it from some program - check out this lib - https://github.com/leonid-shevtsov/headless

over 1 year ago ·
3018

"I don't see that 'scrot' have a 'display' option, so I guess I should export first the 'DISPLAY=:0' variable to be able of taking the screenshot through ssh." scrot is a command line application, i don't understand what is a problem with using it take the screenshot in the remote system you are ssh into (obv with scrot installed) . Also, you can always set timer with scrot to take timed screenshot. Very handy feature. Plus the options are simpler and cover more features.
So i compared yours method with mine on basis of these features.

With that said, i haven't used your version much. So will test it.

over 1 year ago ·
3020

@iafonov Thanks for the link!!!

BTW, I have to check, but it seems like the lib use the interface Xvfb, but I don't know if it could be used against a running X server. I wanted to take a screenshot of what is currently at the display :0.

Do you know if this is possible? Thanks in advance.

over 1 year ago ·
3021

@vinitcool76 I haven't said that there is a problem with 'scrot' taking screenshots on remote systems, just that it's probably that it need to export the DISPLAY variable to be able to access to the X server.

That's normal behavior. I mean, any app (command line or not) to access to an object of the graphical session (for example, the current aspect of the desktop) need to know the DISPLAY where is running.

'import' has a option to specify that variable, instead of export it to your shell environment, but it's just a handy utility. That's what I was saying.

About the 'delay' option, I also think that is a handy feature, and 'import' has it as well. Among others useful features.

But both tools are valid tools for the task. It's good to know them all and decide which one use based on what you really need or you like the most.

Thanks for your comments. Cheers.

over 1 year ago ·
3025

thanks for the detail explanation. :) Cheers!

over 1 year ago ·