Linux – How to use command line and wmctrl to make a window larger than the screen to get a huge screenshot

command linelinuxscreenshotwindow

I use a program which makes a large image which I have to scroll to view. The program has no way to save the image, and I have no access to the source to modify it. The only way I have to get the image from the program is by screenshot. My goal is to save the full size image without having to piece together individual screenshots.

I'm using this script to try taking a screenshot:

#!/bin/bash
window=$(wmctrl -l | grep "Program$" | awk '{print $1}')
wmctrl -v -i -r $window -e '0,0,0,6030,5828'
wmctrl -i -a $window
import -window $window ~/Desktop/screenshot.png

This uses wmctrl to get the window id ($window) for a window named "Program". It then tries to resize the window to the desired dimensions. It uses imagemagick (import) to save a screenshot.png on the user's Desktop. All of this works except the resize step.

I can resize the window using wmctrl -r -e, but sizes greater than the screen size don't work.

I'm using Ubuntu 10.04 and the Gnome Desktop. I run two monitors, but I've tried this with one of them disabled.

Is there a way to resize the window larger than my screen to get a huge screenshot?

Part II:

Thanks to the answer by sdaau, I tried using xrandr to set up screen panning, so as to have a bigger desktop than my monitor.

xrandr --output LVDS --panning 2600x2500

This command makes the laptop screen pan over a 2600×2500 size desktop, even though it can only show 1440×900 at one time. To turn off the panning, I can use a similar command to set total size and with zeroes for the panning section. This gives me back my original laptop display behavior.

xrandr --fb 1440x900 --output LVDS --panning 0x0

This is all done with xrandr, and does not require any Xorg.conf changes (my Ubuntu system doesn't even have an Xorg.conf).

My video card seems to only allow about 6.5 million pixels, even though the maximum dimensions are 8192×8192. That maximum seems to be the maximum for either dimension, but there is a limit to how many pixels can be drawn, which is the width multiplied by the height.

Once I did the screen resize, I tried my script again and got a screenshot. The screenshot however is totally scrambled. I'm not sure if it's unable to take a screenshot of an off-screen window or if it is unable to handle the large dimensions of the window. With the panning display, the window should think it is visible, and the window manager should think it is on-screen. So there is a pixel buffer somewhere with those pixels in it, so there should be a way to get a screenshot.

Maybe there is another method to taking screenshots which might work better than import.

Best Answer

Just tested with import and a window extended beyond / bigger than the screen size; and it seems import will capture an image of the same size as the big window size -- unfortunately all pixels beyond the screen size, and all pixels covered by other windows, will be black.

So maybe the only way is to use xrandr to enlarge screen size (as in 'screen pannning') - or to use something else that will provide larger screen size: for instance, "How can I take browser screenshots at a higher resolution than my browser supports? - Super User" notes:

Use Xephyr to create a nested X session

(Xephyr is apparently in sudo apt-get install xserver-xephyr in Ubuntu)

Hope this helps,
Cheers!

Edit: yup, xrandr works with the usual printscreen for me (also with import, just needs enough space for a terminal to fit, so it doesn't overlap the target window), just note the Virtual size in xorg.conf (see "xrandr: screen cannot be larger than" ...)