2010년 8월 25일 수요일

[프로그래밍] How to take automatic screenshots of websites.






How to take automatic screenshots of websites.

August 23rd, 2007 Posted in Scripting

I have a Mexican website directory, and i wanted to add a screen-shot for every single site that was registered… First i looked for this in the community, but i could not find anything that did the trick. So i started to play around with X, to see how far i could get…


The end result is this: A script that can automatically take screen-shots from websites. On any Linux computer. Even when you are using the desktop!


Preparing:


As im using Fedora, i had to install some extra packages:

xorg-x11-server-Xvfb
ImageMagick


And i Installed Opera. I normally don’t use Opera, but i wanted to run the script as my regular user, and didn’t want to change my configuration from Firefox.


Once you installed Opera, remove all the tool-bars, menus, anything that you do not want in your screen-shot. And test it full screen. thats how your screen-shot will look like. If you wish to use firefox or mozilla(seamonkey) then you will have to configure them in the same manner.


Xvfb is a virtual Xserver, so we can basically do anything we want in there without disrupting the current Xserver that we are working in..


first we have to prepare the virtual Xserver:


In the directory where you want to run your script, create a file X99.cfg, the only content of that file should be localhost.


Doing the work:


Then run the Xvfb server:


Xvfb -auth X99.cfg :11 -screen 0 1024x768x24 >/dev/null 2>&1

Next thing we want to do is start Opera with the right website.


opera -nosession -fullscreen -display :11 "http://www.digg.com" > /dev/null 2> /dev/null &

Now give it 10-20 seconds to load the website, it may take longer on some connections. I prefer to put it 20 seconds, so i make sure that the screen-shot isn’t taken in the middle of a intro flash animation.


Now its time to make the screen-shot


/usr/bin/import -window root -display :11 "temp.jpg"

And to resize it we can use ImageMagick


/usr/bin/convert -thumbnail 180x temp.jpg digg.jpg

Next is to kill Opera and the Xvfb server and we are done, i’m using killall here, which is fine on my system, you may want to write something more intelligent for that.


killall opera
killall Xvfb

And thats all to it!


Its quite easy to script this and process a lot of sites in sequence.






  1. 5 Responses to “How to take automatic screenshots of websites.”



  2. By Shreyas on Aug 26, 2007


    Hey!!


    http://iwebtool.com is also good if you dont want to take the fuss.



  3. By Johan on Aug 26, 2007


    hi, thanks, those services offer low quality , usually with a watermark tained images. Next to that you need link back from every image back to their website.


    If any of that bothers you, the script is a nice solution.



  4. By Richard on Sep 29, 2007


    What version of Fedora are you using? I have tried this on Fedora 7 and I am having all sorts of issues with installing Opera and getting Xvfb to run. Would really like to get this working. Would appreciate if you could help me out. Thanks.



  5. By Richard on Sep 30, 2007


    I ended up getting this to work, but I cannot get the -fullscreen switch to work within Xvfb. Were you able to get it chromeless?



  6. By Johan on Sep 30, 2007


    try to use the crop function of import.


    /usr/bin/import -crop 1024×4000+0+25 -quality 85 -window root -display :11 image.jpg


댓글 없음:

댓글 쓰기