comp.lang.perl.modules-using_Image::Magick_and_Tk::Photo_without_temp_files_for_passing_between_them

This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.



From: "Eric McDaniel" <eric@mcdanielhome.com>
Subject: Image::Magick and Tk::Photo
Newsgroups: comp.lang.perl,comp.lang.perl.modules
Date: Sat, 30 Aug 2003 18:17:07 GMT
Organization: Comcast Online


I am trying to read in a bunch of images and manipulate them using
Image::Magick, then display them using Tk::Photo. I would like to do this
without creating a temp file for each image, since there can be quite a few
of them.

However, I can't make Tk::Photo understand the data returned by
Image::Magick's ImageToBlob() function. Here is the way I had hoped it would
work:

#!perl

use strict;
use warnings;

use Tk;
use Image::Magick;

my $image = Image::Magick->new();
$image->read('c:\Documents and Settings\ericm\My Documents\My
Pictures\earthris.gif');

# Do various Image::Magick manipulations here...
# ...

my $blob = $image->ImageToBlob();

# Set up Tk windows
my $main = MainWindow->new();
my $photo = $main->Photo('img', -format=>'GIF', -data=>$blob );
$main->Label('-image' => 'img', -height=>200, -width=>200)->pack;

MainLoop;

###################################

This code generates the error  "couldn't recognize image data at
C:/Perl/site/lib/Tk/Image.pm line 21." in the call to $main->Photo.
If I create a temp file with $image->write() and read it in using the
$main->Photo(-file=>'...') syntax, it works fine.

Any suggestions?

Thanks in advance.

===

From: "Jack D." <goodcall__1@hotmail.com>
Subject: Re: Image::Magick and Tk::Photo
Newsgroups: comp.lang.perl,comp.lang.perl.modules
Date: Sun, 31 Aug 2003 04:25:37 GMT

((Note addition of two lines to these code:))

"Eric McDaniel" <eric@mcdanielhome.com> wrote:

> I am trying to read in a bunch of images and manipulate them using
> Image::Magick, then display them using Tk::Photo. I would like to do this
> without creating a temp file for each image, since there can be quite a few
> of them.
>
> However, I can't make Tk::Photo understand the data returned by
> Image::Magick's ImageToBlob() function. Here is the way I had hoped it would
> work:
>
> #!perl
>
> use strict;
> use warnings;
>
> use Tk;
> use Image::Magick;

#-------------------------#
use Mime::Base64;
#-------------------------#

>
> my $image = Image::Magick->new();
> $image->read('c:\Documents and Settings\ericm\My Documents\My
> Pictures\earthris.gif');
>
> # Do various Image::Magick manipulations here...
> # ...
>
> my $blob = $image->ImageToBlob();

>
> # Set up Tk windows
> my $main = MainWindow->new();
> my $photo = $main->Photo('img', -format=>'GIF', -data=>$blob );

#-------------------------#
my $photo = $main->Photo('img', -format=>'GIF', -data=>encode_base64($blob) );
#-------------------------#


#######################
> $main->Label('-image' => 'img', -height=>200, -width=>200)->pack;
>
> MainLoop;
>
> ###################################
>
> This code generates the error  "couldn't recognize image data at
> C:/Perl/site/lib/Tk/Image.pm line 21." in the call to $main->Photo.
> If I create a temp file with $image->write() and read it in using the
> $main->Photo(-file=>'...') syntax, it works fine.
>
> Any suggestions?

You have to convert the data to base64 format for Tk to recognize it.
===


the rest of The Pile (a partial mailing list archive)

doom@kzsu.stanford.edu