Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Website screenshot

by Alien (Monk)
on Jan 06, 2007 at 00:26 UTC ( #593234=perlquestion: print w/ replies, xml ) Need Help??
Alien has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks !

I want to make a website screenshot script for my site ... How could that be done ? Any ideas ?

Thanks !

Comment on Website screenshot
Re: Website screenshot
by shonorio (Hermit) on Jan 06, 2007 at 00:34 UTC
    Alien, sorry but I did't understand your question. If you want a script to make a screenshot, try to look CPAN Screenshot. But if you just want to do a screen shot of your site, have you tried the keyboard "PrtSc" ?

    Solli Moreira Honorio
    Sao Paulo - Brazil

      I want the script to be able to take an argument from
      command-line ( site URL , ex:www.google.com ) and return a
      picture of the website , a thumbnail image .
      
        You don't really want a screenshot, then, since there's no screen. You want to render the Web page to a thumbnail image.

        I don't have any good advice for doing that, but maybe that will give you some new keywords to google. :-)

        Good luck!

Re: Website screenshot
by shigetsu (Hermit) on Jan 06, 2007 at 00:39 UTC
    I wouldn't be using Perl for that though,
    scrot - command line screen capture utility
    seems fairly sufficient if you're using Linux.
      I knew about scrot ... but I saw a php script somewhere that
      was able to do website screenshots ( it was commercial ) so
      I thought maybe the same was possible in Perl .
      
        What makes you think they don't use scrot?
Re: Website screenshot
by starX (Chaplain) on Jan 06, 2007 at 01:40 UTC
    You might want to look at Imager::Screenshot. Have a script open a web browser, then run either the win32 or x11 screenshot function, and then close the window. I'm fairly rusty on my Tk though, so I couldn't tell you how to do it off the top of my head.
Re: Website screenshot
by emazep (Priest) on Jan 06, 2007 at 01:53 UTC
    Alien, taking a screenshot of a given HTML page, implies that the mentioned HTML page has been rendered, which is a quite complex task, handled with many difficulties even by modern web browsers.

    Your best option is thus probably using a browser (on the server side by your Perl script) to fetch the given URL and to render the corresponding page, and then using some program to take the actual screenshot (such as scrot), as already suggested also by others.
    It's likely that the PHP script you saw used some external HTML rendering engine/widget under the hood.

    Ciao,
    Emanuele.
        PLEASE REMOVE THIS PAGE FROM YOUR SITE THIS WAS NOT ONE OF OUR STAFF AT http://thumbnailspro.com
Re: Website screenshot
by Anonymous Monk on Jan 06, 2007 at 03:14 UTC
    This will take multiple steps.
    1. First download a copy of the webpage using LWP::Simple
    2. Convert the HTML to PS.
    3. Convert the PS (PostScript) to either a PDF or Gif.
    You'll simply have to google each of the above steps to find out how to do them.
      2. Convert the HTML to PS.

      And after that you'd end up with a PDF or a gif of something that looked like this:

      <html> <head><title>This is an unrendered web page</title></head> <body> . . . </body>

      That's not exactly what the OP is trying to do... :-D

      Gary Blackburn
      Trained Killer

        Actually there is a program called html2ps that translates the rendered html to ps. I haven't had much luck getting it installed - but it would serve to do the trick.

        my @a=qw(random brilliant braindead); print $a[rand(@a)];
Re: Website screenshot
by zentara (Archbishop) on Jan 06, 2007 at 12:43 UTC
    #!/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: Website screenshot
by erroneousBollock (Curate) on Aug 26, 2007 at 19:41 UTC
    You can use Mozilla::Mechanize to drive Mozilla/Firefox to the target site.

    Mozilla::Mechanize seems to be based on Gtk::MozEmbed, which just seems to implement a GTK+ widget using the mozilla embedding API to render the content.

    You should be able to get an X11 window handle for the widget and so then you should be able to use many different methods to obtain the contents of the window as an image.

    It's not generally an easy thing to do.

    On the other hand, there's a Firefox addon called "Screen Grab!" which captures a web page as image in the format of your choice. You might try to automate that in some way (eg, via Javascript and XPCOM APIs).

    -David.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://593234]
Approved by shonorio
Front-paged by shonorio
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-12-28 10:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (180 votes), past polls