Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Trying to fetch image via URL Perl/Tk

by Muskovitz (Scribe)
on Nov 19, 2014 at 12:21 UTC ( #1107736=perlquestion: print w/replies, xml ) Need Help??

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

hey guys i am trying to fetch an IMAGE using URL in Perl/tk but it cant read it heres my line of code.

use Tk; require Tk::Photo; require Tk::JPEG; my $mw=new MainWindow; my $image="http://example.com/background.jpg"; my $shot=$mw->Photo(-file=>"$image",-format=>'jpeg'); $mw->Label(-image=>$shot)->pack; MainLoop;

FAILED! but if you remove the link, cool! Not to mention i am new here!

Replies are listed 'Best First'.
Re: Trying to fetch image via URL Perl/Tk
by Loops (Curate) on Nov 19, 2014 at 17:53 UTC

    Hi, welcome to the monastery.

    Tk::Photo doesn't handle downloading images from a URL. However combined with a pair of additional modules, you can do it yourself:

    use Tk; use Tk::Photo; use Tk::JPEG; use LWP::Simple; use MIME::Base64 qw(encode_base64); my $mw=new MainWindow; my $data = encode_base64 get('http://tinyurl.com/oyzuyjt'); my $shot=$mw->Photo(-data=>$data,-format=>'jpeg'); $mw->Label(-image=>$shot)->pack; MainLoop;
Re: Trying to fetch image via URL Perl/Tk
by jellisii2 (Hermit) on Nov 19, 2014 at 12:54 UTC
    Can TK make the http connection and grab the actual file? I ask in ignorance.

      Uhhmm... i dont think so but i am using Net::FTP to grab the actual image file but i was trying to seek tweaks! for this statement

        Well, that was sorta' crucial information for those who might want to help, wasn't it?


        Questions containing the words "doesn't work" (or their moral equivalent) will usually get a downvote from me unless accompanied by:
        1. code
        2. verbatim error and/or warning messages
        3. a coherent explanation of what "doesn't work actually means.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2021-05-15 10:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (150 votes). Check out past polls.

    Notices?