I need to display a PGM image in a Perl/TK window.
I tried using Tk::Photo, but it doesn't want my PGM data (obtained from
scanimage):
my $p = $top->Photo(-data => $image, -format => 'PGM');
However, I can load it into Image::Magick:
$image->BlobToImage($pgm);
How can I display the image loaded in Image::Magick?
I'd like to avoid storing the image on disk, as it will be sent to a
printer right away, it's just for previewing purposes.
Josef
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
>I need to display a PGM image in a Perl/TK window.
>I tried using Tk::Photo, but it doesn't want my PGM data (obtained from
>scanimage):
>my $p = $top->Photo(-data => $image, -format => 'PGM');
>
>However, I can load it into Image::Magick:
>$image->BlobToImage($pgm);
>
>How can I display the image loaded in Image::Magick?
>I'd like to avoid storing the image on disk, as it will be sent to a
>printer right away, it's just for previewing purposes.
>Josef
Load the blob with ImageMagick as PGM, then chnage the magick
to gif, jpg, or png. Gif is built-in so maybe use it.
#!/usr/bin/perl
use warnings;
use strict;
use Image::Magick;
use Tk;
#use Tk::JPEG;
#use Tk::PNG;
use MIME::Base64;
#fake a PGM then convert it to gif
my $image = Image::Magick->new(
size => "600x600",
);
$image->Read("xc:white");
$image->Draw(
primitive => 'line',
points => "300,100 300,500",
stroke => '#600',
);
# set it as PGM
$image->Set(magick=>'pgm');
#your pgm is loaded here, now change it to gif or whatever
$image->Set(magick=>'gif');
my $blob = $image->ImageToBlob();
# Tk wants base64encoded images
my $content = encode_base64( $blob ) or die $!;
my $mw = MainWindow->new();
my $tkimage = $mw->Photo(-data => $content);
$mw->Label(-image => $tkimage)->pack(-expand => 1, -fill => 'both');
$mw->Button(-text => 'Quit', -command => [destroy => $mw])->pack;
MainLoop;
__END__
zentara
Works like a charm. Now I owe you two ;-)