If you are on linux, you can use this script to take a snapshot of the browser. There is one prerequisite in that you must be on the same virtual desktop as the web browser when you run this script. You also get the whole browser, not just the html. The second script below just grabs the html using Gtk2::Webkit
#!/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:`; #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
or if you just want the html, you can use Gtk2::Webkit
#!/usr/bin/perl use strict; use warnings; use Glib qw/TRUE FALSE/; use Gtk2 -init; use Gtk2::WebKit; my $url = shift || 'http://www.youtube.com/watch?v=9HIybxmMerA'; my $win = Gtk2::Window->new; $win->set_default_size(800, 600); $win->signal_connect(destroy => sub { Gtk2->main_quit }); my $view = Gtk2::WebKit::WebView->new; $view->signal_connect( 'notify::progress' => \&notify_progress, undef +); $view->signal_connect( 'load_finished' => \&load_finished, undef ); my $sw = Gtk2::ScrolledWindow->new; $sw->add($view); my $vbox = Gtk2::VBox->new( FALSE, 6 ); $vbox->set_size_request(0,0); $win->add($vbox); $vbox->set_border_width(2); $vbox->pack_start( $sw,TRUE, TRUE, 0 ); $vbox->pack_start (Gtk2::HSeparator->new, FALSE, FALSE, 0); my $button = Gtk2::Button->new_from_stock('gtk-quit'); $vbox->pack_start( $button, FALSE, FALSE, 0 ); $button->signal_connect( clicked => \&delete_event ); my $button1 = Gtk2::Button->new_from_stock('Screenshot'); $vbox->pack_start( $button1, FALSE, FALSE, 0 ); $button1->signal_connect( clicked => \&screenshot ); $win->show_all; $view->open($url ); Gtk2->main; sub notify_progress{ my $load_progress = $view->get('progress'); print "$load_progress\n"; } sub load_finished{ print "load complete\n"; # screenshot(); # do auto screenshot on full load return 0; } ##################################### sub delete_event { Gtk2->main_quit; return FALSE; } ##################################### sub screenshot{ #we are going to save the $view my ($width, $height) = $view->window->get_size; # create blank pixbuf to hold the image my $gdkpixbuf = Gtk2::Gdk::Pixbuf->new ('rgb', 0, 8, $width, $height); $gdkpixbuf->get_from_drawable ($view->window, undef, 0, 0, 0, 0, $width, $height); #only jpeg and png is supported !!!! it's 'jpeg', not 'jpg' $gdkpixbuf->save ("$0.jpg", 'jpeg', quality => 100); print "screenshot\n"; return FALSE; } #$pixbuf->save ($filename, 'jpeg', quality => '100'); # Currently only a few parameters exist. JPEG images can be saved # with a "quality" parameter; its value should be in the range # [0,100]. Text chunks can be attached to PNG images by specifying # parameters of the form "tEXt::key", where key is an ASCII string of # length 1-79. The values are UTF-8 encoded strings.

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: html to jpeg by zentara
in thread html to jpeg by raja.pallavan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.