I am supplying image data (BMP or PNG) via the -data option to Tk::Photo.
Is it necessary for the data string to be BASE65-encoded?
Own experiments suggest yes, my understanding of the (german)
man-page was different (that I could supply directly the contents of a
file).
Background: I want to transform the image in memory using Imager
or something similar and then display it using Tk::Photo.
Oliver
I found this code in StyledButton.pm
use Tk;
use Tk::PNG;
use Tk::JPEG;
use Tk::Photo;
use MIME::Base64;
sub _setGDImage {
my ($self, $image) = @_;
return $self->Photo(-data => encode_base64($image->png()), -format => 'png');
}
> sub _setGDImage {
> my ($self, $image) = @_;
> return $self->Photo(-data => encode_base64($image->png()), -format =>
> 'png');
> }
To quote from the man-page of Tk::Photo:
"-data => string
Specifies the contents of the image as a string. The string can
contain base64 encoded data or binary data. The format of the
string must be one of those for which there is an image file format
handler that will accept string data."
So, it _should_ be possible to supply binary data. But I don't have figured
out how. On the other hand the above code seems to suggest, that the man-page
is wrong...
At least the encode_base64() doesn't seem to hurt much.
Oliver
No.
Here's a small script that I just wrote:
#! /usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::PNG;
die "usage: $0 png\n" if @ARGV != 1;
my $top = new MainWindow;
my $p = $top->Photo(-format => 'png', -file => $ARGV[0]);
my ($width, $height) = ($p->width, $p->height);
print STDERR "width=$width, height=$height\n";
my $c = $top->Canvas(-width => $width, -height => $height)->pack();
$c->createImage(0, 0, -image => $p, -anchor => 'nw');
$c->bind('all', '<ButtonRelease-1>' => \&show);
MainLoop;
sub show {
my $wid = shift;
my $e = $wid->XEvent;
print $e->x, ', ', $e->y, "\n";
}
--
These are my personal views and not those of Fujitsu Technology Solutions!
Josef Möllers (Pinguinpfleger bei FTS)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://de.ts.fujitsu.com/imprint.html
> Oliver 'ojo' Bedford wrote:
>> Hi,
>>
>> I am supplying image data (BMP or PNG) via the -data option to
>> Tk::Photo.
>> Is it necessary for the data string to be BASE65-encoded?
>
> No.
>
> Here's a small script that I just wrote:
> [...]
> my $p = $top->Photo(-format => 'png', -file => $ARGV[0]);
[...]
Josef, you are using the -file option, whereas I was referring to -data.
Point is, I want to avoid file I/O in order to save time. So I'm
manipulating an image in memory and supply it via -data to Tk::Photo.
Oliver
Oops. Sorry.
I just tried and apparently the -data requires the data to be base64
encoded, despite the manpage saying:
"The string can contain base64 encoded data or binary data.".
I tried by reading the entire image into a string and then calling
encode64() from the MIME::Base64 module.
It failed without the encoding:
couldn't recognize image data at /usr/lib/perl5/Tk/Image.pm line 21.
and worked with the encoding.
Josef