Hi,
Can someone please point out where my reasoning is flawed
concerning base64 encoding.

A question recently came up in the Tk newsgroup on how to
display a jpg image with Tk, directly from a url.

I could easily do it if I mirrored a temporary jpg file on the local
harddrive, then displayed it; but to do it by displaying what is in
memory alone, required MIME::Base64 encoding.
########################################################
#!/usr/local/bin/perl -w
use strict;
use Tk;
use Tk::JPEG;
use LWP::Simple;
use MIME::Base64;

my $URL = shift || '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;
###########################################################

The question for me is why do you need to "encode_base64"?
First, shouldn't the file be incoming  in binary form, so that I could
just display the $content directly?

Second, assuming it is necessary to MIME encode the binary file for
transfer over the internet, shouldn't I need to use "decode" instead
of "encode" on the receiving end?

In the following script, I mirror the file and display it, and there is
no need for MIME, so where is that encoding process occuring?

###########################################################
#!/usr/bin/perl -w
use strict;
use Tk;
use Tk::JPEG;
use LWP::Simple;

my $URL = shift || 'http://zentara.net/2uni2.jpg';
my $rc = mirror( $URL,'tmp.jpg');

my $mw  = MainWindow->new();
my $image = $mw->Photo(-file => 'tmp.jpg');
$mw->Label(-image => $image)->pack(-expand => 1, -fill => 'both');
$mw->Button(-text => 'Quit', -command => [destroy => $mw])->pack;
MainLoop;
###########################################################

 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to