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

Is this even possible? I'd like to display a jpeg from website X in a perl/Tk app? For example:
#!/usr/bin/perl -w use strict; use Tk; use Tk::JPEG; my $main = MainWindow->new(); my $image = $main->Photo('-format' => 'jpeg', -file => 'http://www.som +ewebsite/photos/image1.jpg'); my $label= $main->Label(-image => $image)->pack(); MainLoop
Thanks

Replies are listed 'Best First'.
Re: view online jpeg in Tk ?
by zentara (Cardinal) on Sep 11, 2006 at 19:50 UTC
    This will do it, without creating any temp image file. You need to get the binary image with LWP, Base64encode it to please Tk, then use the -data option.
    #!/usr/bin/perl -w use strict; use Tk; use Tk::JPEG; use LWP::Simple; use MIME::Base64; my $URL = 'http://zentara.net/2uni2.jpg'; my $content = encode_base64(get($URL)) or die $!; my $mw = MainWindow->new(); my $image = $mw->Photo(-data => $content); $mw->Label(-image => $image)->pack(-expand => 1, -fill => 'both'); $mw->Button(-text => 'Quit', -command => [destroy => $mw])->pack; MainLoop; ############################################# #1 liner # perl -MLWP::Simple -MMIME::Base64 -MTk -MTk::JPEG -e '$mw=tkinit; # $mw->Label(-image => $mw->Photo(-data => encode_base64(get(shift))) +)->pack;MainLoop' # http://...

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      pretty clever..Thanks alot, thats perfect!
Re: view online jpeg in Tk ?
by hgolden (Pilgrim) on Sep 11, 2006 at 19:29 UTC
    My impression is that you can't, because the file option needs a filepath, not a URL. However, you should be able to do this in a two-step form by first getting the image, and then loading it locally using the Photo widget. Try Image::Grab for getting the image: http://search.cpan.org/~mahex/Image-Grab-1.4.2/

    Hope this helps

    Hays