?

Log in

No account? Create an account
brad's life [entries|archive|friends|userinfo]
Brad Fitzpatrick

[ website | bradfitz.com ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

How to make web screenshots [May. 13th, 2004|11:43 am]
Brad Fitzpatrick
[Tags|, , ]

$ vncserver -geometry 800x800 -depth 24
$ DISPLAY=:1 mozilla-firefox -P "Screenshot" &
$ DISPLAY=:1 mozilla-firefox -P "Screenshot" -remote "openurl(javascript:window.open('http://www.livejournal.com/','','fullscreen=yes,toolbar=no,width=800,height=800'))"
$ DISPLAY=:1 import -window root -resize 200x200 lj-shot.jpg
$ eog lj-shot.jpg

LiveJournal

score
LinkReply

Comments:
[User Picture]From: taral
2004-05-13 11:47 am (UTC)
Cute. Doesn't have to be fullscreen though. import will import from a selected window if you want.
(Reply) (Thread)
[User Picture]From: brad
2004-05-13 11:51 am (UTC)
yeah, but then i have to figure out how to get the window-id, and I'm lazy
(Reply) (Parent) (Thread)
[User Picture]From: gaal
2004-05-13 12:48 pm (UTC)
Open the browser with -name screenshot and call import with the same option. (Not actually tested.)
(Reply) (Parent) (Thread)
[User Picture]From: brad
2004-05-13 01:10 pm (UTC)
I was actually reading your raise.c code and playing with for a while, thinking that might provide a route to resize windows. (before I remembered -remote loadURL(javascript:....)
(Reply) (Parent) (Thread)
[User Picture]From: gaal
2004-05-13 03:12 pm (UTC)
Heh, I only wrote four lines there. The rest was lifted from random x client code. Happily, this practice is common, so lots of things work with both -id and -name :)


(Now I'm beginning to wonder if there's an X shell, like say perl is a libc shell.)
(Reply) (Parent) (Thread)
[User Picture]From: mart
2004-05-13 11:48 am (UTC)

I wonder how hard it'd be just to get Gecko to render to an offscreen bitmap and save that, rather than all this (admittedly rather cool) jiggery-pokery.

What's eog, anyway?

(Reply) (Thread)
[User Picture]From: mart
2004-05-13 11:49 am (UTC)

After posting that I realised it was just a matter of doing apt-cache show eog… duh.

(Reply) (Parent) (Thread)
[User Picture]From: kvance
2004-05-13 11:50 am (UTC)
Nice!
(Reply) (Thread)
[User Picture]From: crschmidt
2004-05-13 12:41 pm (UTC)
I'd do:

$ DISPLAY=:1 import -window root lj-shot.jpg
$ convert -resize 200x200 lj-shot.png lj-shot-small.png

But I like having a big version and a little version on my screenshots.
(Reply) (Thread)
From: (Anonymous)
2004-05-13 04:07 pm (UTC)
I live with the borders and use xwd and imagemagik:
sleep 5 && xwd | display - -resize 80%

To improve on your method, use Xnest instead of vncserver.
(Reply) (Thread)
[User Picture]From: brad
2004-05-13 05:05 pm (UTC)
Good info. Thanks!
(Reply) (Parent) (Thread)
[User Picture]From: brad
2004-05-13 05:09 pm (UTC)
Ugh.... the window has to be in the foreground for that to work? That makes it a lot harder to automate. I think we'll keep using vncserver.
(Reply) (Parent) (Thread)
From: (Anonymous)
2004-05-14 03:40 pm (UTC)
Actually, xwd takes a -name (WM_NAME aka the window title) or -id attribute. The WM_NAME for mozilla is usually just the html title + ' - Mozilla'.
(Reply) (Parent) (Thread)
[User Picture]From: brad
2004-05-14 03:53 pm (UTC)
Regardless, using Xnest means we can't automate it. We'll just keep using vncserver. I see no drawbacks to it.
(Reply) (Parent) (Thread)
From: (Anonymous)
2006-01-04 12:26 am (UTC)
I run firefox in Xvfb so I can do offscreen screendumps of it
for printing.
Its important that its offscreen as some of the images are much
higher or wider than my hardware display.
It would be nice if you could somehow get konqueror or firefox to
render a web page to a bitmap without all this flakey stuff though.

(Reply) (Parent) (Thread)
From: (Anonymous)
2004-05-13 06:01 pm (UTC)

Clarifications

Could you translate that? How does this work? What is "eog"?
Thx
Dumky
(Reply) (Thread)
[User Picture]From: brad
2004-05-13 06:14 pm (UTC)

Re: Clarifications

eog is just an image viewer. That command isn't necessary.
(Reply) (Parent) (Thread)
[User Picture]From: mendel
2004-05-13 06:19 pm (UTC)
Score. Ages ago I saw sippey's blogsnaps and wanted to automate them, and, well, see this or this or this. Thanks for the kick to get it done.

The script to grab the whole thing is right here. If anyone else can do the bit that uses xwininfo more gracefully I'd be a happy mendel.
(Reply) (Thread)
[User Picture]From: brad
2004-05-13 06:26 pm (UTC)
Why use xwininfo at all? Just import the whole window, as long as you're making a new X display. (Which is why I did -window root)
(Reply) (Parent) (Thread)
[User Picture]From: mendel
2004-05-13 06:43 pm (UTC)
Because the height of the whole root window has to be >= the height of the longest webpage you might want to capture. If you import the root window when a client window on it goes off the bottom of the screen, then you only get the visible part of the client window, so you have to make the X display big enough to fit the window (which you haven't measured yet), and then resize the browser to the height of the page.

At that point you've got a worst-case-height root window and an exact-size browser window, so you import the browser window.
(Reply) (Parent) (Thread)
[User Picture]From: brad
2004-05-13 07:18 pm (UTC)
Oh, duh. I forgot you were doing the tall thing. (Was thinking of the script's applicability towards our need....)
(Reply) (Parent) (Thread)
From: edge_walker
2004-05-15 06:23 am (UTC)

How about this?

xwininfo -root -children -display $XDISPLAY \
| sed '1,/children:/d; s/^ *\(0x[0-9a-f]\+\).*/\1/; T; q'

Despite defining $XDISPLAY there are hardwired :1 all over, btw.

(Reply) (Parent) (Thread)
[User Picture]From: bitwise
2004-05-20 02:14 pm (UTC)
That's pretty cool. A few problems:

- Error checking would be nice- There was already a vncserver running on :1 so the new vncserver launch failed but it went ahead and tried to launch windows on the existing :1. Note the echo message is wrong; always says :1 even if I change it to something else in the script.
- Tried it on a redhat 8 machine with mozilla 1.0, and it fails. (Says "No running window found"). Don't know why.
- Wouldn't defaulting to PNG make more sense than JPEG? Given that web pages tend to have lots of hard-edged figures that artifact badly in jpeg.
(Reply) (Parent) (Thread)
[User Picture]From: bitwise
2004-05-20 02:50 pm (UTC)
Installed firefox 0.8, same error. Any idea what this would be?

$ ./webshot http://www.slashdot.org slashdot.png
starting X on :27

New 'X' desktop is spike.xxxxxx.com:27

Starting applications specified in /home/me/.vnc/xstartup
Log file is /home/me/.vnc/spike.xxxxxx.com:27.log

launching browser
Xlib:  extension "RENDER" missing on display ":27.0".
opening http://www.slashdot.org
No running window found.
resizing
No running window found.
importing
import: Unable to read X window image (0x4001f3).
import: Missing an image file name.
killing X server
Killing Xvnc process ID 12402
The application 'Gecko' lost its connection to the display :27.0;
most likely the X server was shut down or you killed/destroyed
the application.
(Reply) (Parent) (Thread)
[User Picture]From: bitwise
2004-05-20 03:56 pm (UTC)
Tricks to make it go fast:

- hack vncserver script that doesn't run xstartup stuff, window managers, etc. (wish there was a vncserver option to do this).

- run browser "about:blank" so it doesn't bother rendering a home page first.

For the mozilla commandline challenged, -P "Screenshot" selects a profile named "Screenshot" so you better have one pre-made or it'll hang on the profile selection screen. $BROWSER -CreateProfile Screenshot will take care of this.
(Reply) (Thread)
[User Picture]From: brad
2004-05-20 04:08 pm (UTC)
My setup was already doing that, so I didn't really document it.

I'm sure there's a vncserver option to specify your xinit settings, but mine happen to be blank anyway.
(Reply) (Parent) (Thread)
[User Picture]From: bitwise
2004-05-20 04:45 pm (UTC)
Actually, I've been staring at the vncserver script, and I don't see an option to skip xinit-like stuff.

Only things I can think of are (a) modifying vncserver or (b) hacking up an xinit script that detects that it's being run in the screenshot script (environment variable?)

I wanted to preserve an existing working VNC setup that does have a window manager.
(Reply) (Parent) (Thread)
[User Picture]From: tyomych
2005-10-22 03:12 pm (UTC)
Hi Brad
Found your post via Google and thought you possibly could help me. Following your example I experienced the next problems:
1. $ DISPLAY=:1 mozilla-firefox -P "Screenshot" -remote "openurl(javascript:window.open('http://www.livejournal.com/','','fullscreen=yes,toolbar=no,width=800,height=800'))"
This hangs. I mean it does not return shell. Is it ok? Suspect not.
2. Not sure whther it makes sense to do this after the previous step failed but still:
$ DISPLAY=:1 import -window root -resize 200x200 lj-shot.jpg
This displays "import" help and does nothing.

May be you can clear out these things. Thank you.

PS Sorry if you do not encourage such comments.
(Reply) (Thread)