Skip Menu |

This queue is for tickets about the Tk CPAN distribution.

Report information
The Basics
Id: 35652
Status: resolved
Priority: 0/
Queue: Tk

People
Owner: Nobody in particular
Requestors: info [...] gknw.de
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Photo(-data => $string) not working properly
Date: Tue, 6 May 2008 04:34:42 +0200
To: bug-Tk [...] rt.cpan.org
From: Guenter Knauf <info [...] gknw.de>
Hi, while testing with Tk in order to display images I found that: - on Linux Photo(-data => $string) works only with gif images - on Win32 Photo(-data => $string) doesnt work at all This is the error when using non-gif images: couldn't recognize image data at /usr/lib/perl5/vendor_perl/5.8.8/i586-linux-thread-multi/Tk/Image.pm line 21. I've written a test sample to demonstrate the issue; it can take optional arguments; without arguments -format => gif and -data => $string is used; tkimgx.pl works on Linux, but on Win32 it only displays a black image. tkimgx.pl -p tries to use -format => png, -data = $string, but produces the error message above. tkimgx.pl -j tries to use -format => jpeg, -data = $string, but produces the error message above. tkimgx.pl -p -f tkimgx.pl -j -f use -file = 'image.type' and work on both platforms, and: tkimgx.pl -f works also on Win32 with -format => gif. Test script below and attached: #!/usr/bin/perl -w # CMD sample to fetch a remote web page image with LWP # and then displays it with the Perl Tk framework. use strict; use LWP::UserAgent; use Tk; use Tk::widgets qw/PNG JPEG/; use Tk::Dialog; use Getopt::Std; use vars qw/$opt_f $opt_j $opt_k $opt_p/; getopts('fjkp'); my $version = '0.0.1'; my $url = 'http://www.perl.org/simages/lcamel.gif'; $url = 'http://www.cpan.org/misc/jpg/cpan.jpg' if ($opt_j); $url = 'http://search.cpan.org/s/img/cpan_banner.png' if ($opt_p); my $itype = substr($url, rindex($url, '.') + 1); my $fname = 'tmp.' . $itype; $itype = 'jpeg' if ($itype eq 'jpg'); my $ua = new LWP::UserAgent(agent => "$0/$version"); my $req = new HTTP::Request('GET', $url); my $res = $ua->request($req); die $res->status_line . "\n" if (!$res->is_success); if ($opt_f) { open(O,">$fname") or die "Couldn't open $fname: $!"; binmode O; print O $res->content; close(O) or die "Couldn't close $fname: $!"; } my $mw = new MainWindow; $mw->title('Tk-Image'); $mw->Label('-text' => $url)->pack; my $im; if ($opt_f) { $mw->Label('-text' => $fname)->pack; $im = $mw->Photo(-format => $itype, -file => $fname); } else { $im = $mw->Photo(-format => $itype, -data => $res->content); } $mw->Label('-image' => $im)->pack; MainLoop; if (($opt_f) && (!$opt_k)) { unlink $fname; } Would be great if the -data option also works with png and jpeg, and consitently on all platforms. BTW. just a guess: perhaps there's a binmode() call missing which makes the gif appear as black image on Win32? Guenter.
#!/usr/bin/perl -w # CMD sample to fetch a remote web page image with LWP # and then displays it with the Perl Tk framework. use strict; use LWP::UserAgent; use Tk; use Tk::widgets qw/PNG JPEG/; use Tk::Dialog; use Getopt::Std; use vars qw/$opt_f $opt_j $opt_k $opt_p/; getopts('fjkp'); my $version = '0.0.1'; my $url = 'http://www.perl.org/simages/lcamel.gif'; $url = 'http://www.cpan.org/misc/jpg/cpan.jpg' if ($opt_j); $url = 'http://search.cpan.org/s/img/cpan_banner.png' if ($opt_p); my $itype = substr($url, rindex($url, '.') + 1); my $fname = 'tmp.' . $itype; $itype = 'jpeg' if ($itype eq 'jpg'); my $ua = new LWP::UserAgent(agent => "$0/$version"); my $req = new HTTP::Request('GET', $url); my $res = $ua->request($req); die $res->status_line . "\n" if (!$res->is_success); if ($opt_f) { open(O,">$fname") or die "Couldn't open $fname: $!"; binmode O; print O $res->content; close(O) or die "Couldn't close $fname: $!"; } my $mw = new MainWindow; $mw->title('Tk-Image'); $mw->Label('-text' => $url)->pack; my $im; if ($opt_f) { $mw->Label('-text' => $fname)->pack; $im = $mw->Photo(-format => $itype, -file => $fname); } else { $im = $mw->Photo(-format => $itype, -data => $res->content); } $mw->Label('-image' => $im)->pack; MainLoop; if (($opt_f) && (!$opt_k)) { unlink $fname; }
Subject: Re: [rt.cpan.org #35652] Photo(-data => $string) not working properly
Date: 06 May 2008 21:22:09 +0200
To: bug-Tk [...] rt.cpan.org
From: Slaven Rezic <slaven [...] rezic.de>
"Guenter Knauf via RT" <bug-Tk@rt.cpan.org> writes: Show quoted text
> Mon May 05 22:34:36 2008: Request 35652 was acted upon. > Transaction: Ticket created by info@gknw.de > Queue: Tk > Subject: Photo(-data => $string) not working properly > Broken in: (no value) > Severity: (no value) > Owner: Nobody > Requestors: info@gknw.de > Status: new > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=35652 > > > > Hi, > while testing with Tk in order to display images I found that: > - on Linux Photo(-data => $string) works only with gif images > - on Win32 Photo(-data => $string) doesnt work at all > > This is the error when using non-gif images: > couldn't recognize image data at /usr/lib/perl5/vendor_perl/5.8.8/i586-linux-thread-multi/Tk/Image.pm line 21. > > I've written a test sample to demonstrate the issue; it can take optional arguments; > without arguments -format => gif and -data => $string is used; > tkimgx.pl > works on Linux, but on Win32 it only displays a black image. > tkimgx.pl -p > tries to use -format => png, -data = $string, but produces the error message above. > tkimgx.pl -j > tries to use -format => jpeg, -data = $string, but produces the error message above. > tkimgx.pl -p -f > tkimgx.pl -j -f > use -file = 'image.type' and work on both platforms, and: > tkimgx.pl -f > works also on Win32 with -format => gif. > > Test script below and attached: >
[...] Show quoted text
> > Would be great if the -data option also works with png and jpeg, and consitently on all platforms. > BTW. just a guess: perhaps there's a binmode() call missing which makes the gif appear as black image on Win32? >
Tk::Photo traditionally only accepted base64 encoded data for the -data option (this is an unlucky heritage of the Tcl roots of Tk). Since Tk804.028 there's at least support for binary GIF data. I suspect that your Windows box only runs Tk804.027 which does not have this feature yet. Support for binary JPEG and PNG data may appear in next versions. I admit that the documentation is not clear in this topic, but at least base64 is mentioned there. To fix your script, just add use MIME::Base64 qw/encode_base64/; to the top and use $im = $mw->Photo(-format => $itype, -data => encode_base64 $res->content); to create the Photo object. Regards, Slaven -- Slaven Rezic - slaven <at> rezic <dot> de tkruler - Perl/Tk program for measuring screen distances http://ptktools.sourceforge.net/#tkruler
Subject: Re: [rt.cpan.org #35652] Photo(-data => $string) not working properly
Date: Wed, 7 May 2008 02:04:38 +0200
To: bug-Tk [...] rt.cpan.org
From: Guenter Knauf <info [...] gknw.de>
Hi Slaven, Show quoted text
> Tk::Photo traditionally only accepted base64 encoded data for the > -data option (this is an unlucky heritage of the Tcl roots of Tk). > Since Tk804.028 there's at least support for binary GIF data. I > suspect that your Windows box only runs Tk804.027 which does not have > this feature yet. Support for binary JPEG and PNG data may appear in > next versions. I admit that the documentation is not clear in this > topic, but at least base64 is mentioned there.
Show quoted text
> To fix your script, just add
Show quoted text
> use MIME::Base64 qw/encode_base64/;
Show quoted text
> to the top and use
Show quoted text
> $im = $mw->Photo(-format => $itype, -data => encode_base64 > $res->content);
thank you very much! That works now great on both Linux and Win32. Although I found in one bug report (the one with the memory leak) that the o.p. used base64, I didnt realize that it might be mandatory, especially since it worked for gif without. Ok, so you might close this bug now, and probably also add a sentence to the docu that base64 is mandatory unless you make binary format available too for png and jpeg... BTW, what about tiff? Any plans to bundle this also? Thanks, Guenter.
CC: undisclosed-recipients: ;
Subject: Re: [rt.cpan.org #35652] Photo(-data => $string) not working properly
Date: Tue, 6 May 2008 17:07:17 -0700
To: Guenter Knauf via RT <bug-Tk [...] rt.cpan.org>
From: Ilya Zakharevich <nospam-abuse [...] ilyaz.org>
On Tue, May 06, 2008 at 08:04:41PM -0400, Guenter Knauf via RT wrote: Show quoted text
> Ok, so you might close this bug now, and probably also add a sentence to the docu that base64 is mandatory unless you make binary format available too for png and jpeg... > BTW, what about tiff? Any plans to bundle this also?
IMO, GD format is more important. Then one would just add TIFF input to GD. ;-) Yours, Ilya
Subject: Re: [rt.cpan.org #35652] Photo(-data => $string) not working properly
Date: Wed, 7 May 2008 03:17:17 +0200
To: bug-Tk [...] rt.cpan.org
From: Guenter Knauf <info [...] gknw.de>
Hi Ilya, Show quoted text
> IMO, GD format is more important. Then one would just add TIFF input > to GD. ;-)
well, in fact we have already TIFF support in the next upcoming libgd - we would need to get Lincoln Stein then to add it to GD... and BTW. we have also recently got BMP support in libgd.... just not sure if these are only with libgd 2.1, or also for current 2.0 line.... nice eh?! greetz, Guenter.
Subject: Re: [rt.cpan.org #35652] Photo(-data => $string) not working properly
Date: 07 May 2008 22:47:03 +0200
To: bug-Tk [...] rt.cpan.org
From: Slaven Rezic <slaven [...] rezic.de>
"Guenter Knauf via RT" <bug-Tk@rt.cpan.org> writes: Show quoted text
> Queue: Tk > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=35652 > > > Hi Slaven,
> > Tk::Photo traditionally only accepted base64 encoded data for the > > -data option (this is an unlucky heritage of the Tcl roots of Tk). > > Since Tk804.028 there's at least support for binary GIF data. I > > suspect that your Windows box only runs Tk804.027 which does not have > > this feature yet. Support for binary JPEG and PNG data may appear in > > next versions. I admit that the documentation is not clear in this > > topic, but at least base64 is mentioned there.
>
> > To fix your script, just add
>
> > use MIME::Base64 qw/encode_base64/;
>
> > to the top and use
>
> > $im = $mw->Photo(-format => $itype, -data => encode_base64 > > $res->content);
> > thank you very much! That works now great on both Linux and Win32. > Although I found in one bug report (the one with the memory leak) that the o.p. used base64, I didnt realize that it might be mandatory, especially since it worked for gif without. > > Ok, so you might close this bug now, and probably also add a sentence to the docu that base64 is mandatory unless you make binary format available too for png and jpeg... > BTW, what about tiff? Any plans to bundle this also? >
No, I don't think so. The Perl/Tk was distribution always had zero dependencies (well almost, you need the X11 libraries and include files). For Tk::PNG and Tk::JPEG the complete libpng, zlib and libjpeg are bundled together with Perl/Tk. I am reluctant to do the same with Tk::TIFF, because it's a rather uncommon image format. There's Tk::TIFF at CPAN, and this should be sufficient, I think. Regards, Slaven -- Slaven Rezic - slaven <at> rezic <dot> de tktimex - time recording tool http://sourceforge.net/projects/ptktools/