Eradicatore has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm wondering if anyone knows of a way to use image magick images directly in the "-image" argument of a Perl/Tk Button. I know I could read in the image with image magick, modify it, and write it to a file and then load that file in with Photo() but I was hoping for a less convoluted way. Thanks for any info!

Justin Eltoft

"If at all god's gaze upon us falls, its with a mischievous grin, look at him" -- Dave Matthews

Replies are listed 'Best First'.
Re: Image Magick and Tk
by grummerX (Pilgrim) on Mar 05, 2002 at 11:35 UTC
    You can do this by using Image::Magick's ImageToBlob function and encoding the data with MIME::Base64.
    #!/usr/bin/perl -w use strict; use Tk; use Image::Magick; use MIME::Base64; my $mw = MainWindow->new; my $image = Image::Magick->new; $image->Read('foo.gif'); # Perform any Magick manipulation here ... my ($blob) = $image->ImageToBlob(); my $buttonImage = $mw->Photo(-data => encode_base64($blob)); $mw->Button(-image => $buttonImage)->pack; MainLoop;
    Thanks to Jouke for the pointer on using MIME::Base64 to encode Tk images.

    -- grummerX