For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > October 2006 > HTML to Image Module?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author HTML to Image Module?
Raphael Brunner

2006-10-06, 6:57 pm

Dear Users

does anyone know a perl-Module which can make a image (png/jpg/...) from
a website?

Thanks a lot for all ideas...

Greetings, Raphael
nobull67@gmail.com

2006-10-07, 7:58 am



On Oct 7, 12:43 am, l...@gmx.ch (Raphael Brunner) wrote:
> Dear Users
>
> does anyone know a perl-Module which can make a image (png/jpg/...) from
> a website?
>
> Thanks a lot for all ideas...
>


I don't know the answers but I recall seeing some discussion when this
exact same question was asked in comp.lang.perl.*. I suggest you take a
look at those threads on a Usenet archive such a google groups.

Rendering a web page is a complicated thing basically you need a full
graphical web browser that you can embed.

Zentara

2006-10-07, 7:58 am

On Sat, 7 Oct 2006 01:43:17 +0200, lilo-@gmx.ch (Raphael Brunner) wrote:

>Dear Users
>
>does anyone know a perl-Module which can make a image (png/jpg/...) from
>a website?
>
>Thanks a lot for all ideas...
>
>Greetings, Raphael


Asked before. I don't think there is a module, but it probably is easy
enough to do. There are glitches. Like what if a popup appears that asks
if you want a cookie, or accept a cert.

If you are on linux, you can get the xid of mozilla ( or your browser),
load the website with the remote command, then grab a snap shot
with ImageMagick's import method, which takes an xid.

Import's Special Input Sources:
text: Read and convert a text file to an image
txt: Read the output text format of txt:
x: import the user selected X window window
x:id import the window the the X window ID

So something like this pseudocode:

#!/usr/bin/perl
use warnings;
use strict;
use Image::Magick;

#get xid of browser ( up to you ) like from xwininfo
my $xid = shift;

#open the url and wait for it to load a bit of time
my $url = 'http://somewhere.com';
`mozilla -remote "openURL($url, new-tab)"` ;
# `mozilla -remote "openURL($url, new-window)"` ;
sleep(5);

my $blob = `import x:$xid 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(time.'.jpg');
__END__




--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
Zentara

2006-10-07, 7:58 am

On Sat, 7 Oct 2006 01:43:17 +0200, lilo-@gmx.ch (Raphael Brunner) wrote:

>Dear Users
>
>does anyone know a perl-Module which can make a image (png/jpg/...) from
>a website?
>
>Thanks a lot for all ideas...
>
>Greetings, Raphael


Here is a script that works, but it's a bit clunky.

#!/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: - `;

my $blob = `import -window 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
__END__


--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com