proactive1 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, is there a script available for captureing screenshots or thumbnails from a list of urls?

Replies are listed 'Best First'.
Re: Screenshots from URL's
by fenLisesi (Priest) on Apr 23, 2007 at 17:54 UTC
Re: Screenshots from URL's
by zentara (Cardinal) on Apr 23, 2007 at 21:20 UTC
    Heres a more finished version. The X11::WmCtrl module will: find your browser's desktop and windowid, switch desktops for you, keep your script from obscuring the browser, and snap a thumbnail. Works on linux with ICEWM, not tested otherwise.
    #!/usr/bin/perl use warnings; use strict; use Image::Magick; use X11::WMCtrl; use Data::Dumper; my $wmctrl = X11::WMCtrl->new; printf("window manager is %s\n", $wmctrl->get_window_manager->{name}); my @windows = $wmctrl->get_windows; my $wid; # x window id my $host; # virtual desktop foreach my $app(@windows){ my $title = $app->{title}; if( $title =~ /Mozilla/i){ print "$title\n"; print Dumper(\$app),"\n\n"; $wid = $app->{id}; $host = $app->{host}; } } $wmctrl->switch($host); #must be on same virtual desktop as the browser #works my $blob = `import -window $wid jpg:`; # now $blob is in memory and you can do what you # want with it. my $output = Image::Magick->new(magick=>'jpg'); $output->BlobToImage( $blob ); $output->Resize(geometry=>'160x120'); $output->Write( $0.'.jpg'); exit; # png works too

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      Thank you much for your input.
Re: Screenshots from URL's
by Moron (Curate) on Apr 23, 2007 at 18:01 UTC
    If you want to capture how IE renders it on Windows, there's Win32::CaptureIE. I coudn't find any Linux equivalents of that, although I suppose I can just about imagine using WINE to emulate Windows, but getting that to work with the module would tend to make a pig's breakfast look like lunch at Chez Nico.
    __________________________________________________________________________________

    ^M Free your mind!

Re: Screenshots from URL's
by zentara (Cardinal) on Apr 23, 2007 at 20:21 UTC
    Update: see better script below using X11::WMCtrl.

    If you are running linux, this will do it, but there are some little tricks you need to be careful of, like finding the window id of the browser, and making sure you are on the same virtual desktop as the browser when running this script. This is not a polished/finished script, it just shows you the steps needed to do it.

    #!/usr/bin/perl use warnings; use strict; use Image::Magick; #must be on same virtual desktop as the browser #assume browser's xwindow id = 0xa00022 #use xwininfo to find it #xwininfo -name Mozilla #my $blob = `import -window 0xa00022 jpg: - `; sleep 5; #allows you time to minimize this script #else it will be on top #works my $blob = `import -window 0xa00022 jpg:`; # the x: stuff dosn't seem to work #my $blob = `import x: 0xa00022 jpg:`; #my $blob = `import -`; #postscript produced #print "$blob\n"; # now $blob is in memory and you can do what you # want with it. my $output = Image::Magick->new(magick=>'jpg'); $output->BlobToImage( $blob ); #$output->Resize(geometry=>'160x120'); $output->Write( $0.'.jpg'); exit; # png works too

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: Screenshots from URL's
by dynamo (Chaplain) on Apr 25, 2007 at 01:00 UTC
    Another option -- Check out the service provided by browsershots.org, they will get you screenshots of URLS on a variety of different machines and browsers. It's not instantaneous, but it's free.

    Also it's a web interface, but writing a perl wrapper around that web interface would not be difficult.