Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

save browser's result to image file

by Anonymous Monk
on Apr 23, 2003 at 08:44 UTC ( #252480=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

It is possible to save some url's result document(from IE) to image with Win32::OLE?

if it is possible
show me an example or let me know a link about taht.
else
Is there a way to do that?

Thank you.

Comment on save browser's result to image file
Re: save browser's result to image file
by Anonymous Monk on Apr 23, 2003 at 10:10 UTC
    I imagine it is possible, but not how you think. IE cannot, has never been able to, and probably never will, safe webpages as images. You can however take a screenshot, and save that as an image (through use of pbrush.exe or whatever -- there are a few ways).

    The Win32::OLE docs say it all (you have a lot of research to do).

Re: save browser's result to image file
by BrowserUk (Pope) on Apr 23, 2003 at 11:16 UTC

    I don't know if it's possible using OLE, but using Win32::GuiTest (a brilliant tool) and Win32::Clipboard it is almost trivial.

    #! perl -slw use strict; use Win32::GuiTest qw[FindWindowLike GetWindowText SetForegroundWindow + SendKeys]; use WIn32::Clipboard; my $clip = Win32::Clipboard->new(); my @windows = FindWindowLike(0, "Internet Explorer\$"); #Find it for (@windows) { SetForegroundWindow($_); # Make it active sleep 2; # Give IE chance to re-draw it's window. # Send the Alt-print screen key sequence to copy the active window + to the clipboard SendKeys("%{PRTSCR}"); } if (my $bitmap = $clip->GetBitmap()) { local $\; my $bmpfile = 'snapshot[' . time() . '].bmp'; open my $bmp, '>', $bmpfile or die $!; binmode $bmp; print $bmp $bitmap; close $bmp; print "Bitmap written to $bmpfile\n"; } else { die "Couldn't get bitmap from clipboard"; }

    This code is just a throw-together and could do with much enhancment. Converting the bmp to a .png or .jpg would be a good start as the .bmp file sizes are enormous.

    NOTE: As is, this will create a bmp for every window that has "Internet Explorer" at the end of it titlebar text. You may want to limit this my being more selective.


    Examine what is said, not who speaks.
    1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
    2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
    3) Any sufficiently advanced technology is indistinguishable from magic.
    Arthur C. Clarke.
•Re: save browser's result to image file
by merlyn (Sage) on Apr 23, 2003 at 14:01 UTC
    Consider ImageMagick. If you can get all the pieces to work, then this works:
    convert http://www.stonehenge.com/index.html image.gif
    A lot of stuff has to be installed, but it looks like Magick when it works!

    And then if you're really lucky, you can also get Perl to drive that with PerlMagick.

    Much Smoke. Many Mirrors. But pretty spiffy when it comes together.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2014-08-30 22:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls