in reply to Re: TK::Photo -file -data
in thread TK::Photo -file -data

Yes - that's correct. But my problem is how to read / parse the gif file and correctly format the imagedata for the -data option.

Below is an example for doing the job using jpeg images and GD - but i need to use gif's (or perhaps png's) and I would like to awoid having to use GD when showing the images in the final script which should get it's parsed image data from a dbmopned hash. So the question is...

Does anyone know how to parse the imagedata from a Gif?

Thanx in advance, Søren Schimkat
#!/usr/bin/perl use GD; use Tk; use Tk::JPEG; use MIME::Base64; my $im = GD::Image->new('image.jpg'); my $img = encode_base64($im->jpeg()); my $main = MainWindow->new(); my $image = $main->Photo("button", -data => $img, -format => 'jpeg'); my $label= $main->Label(-image => "button"); $label->grid(-in => $main); MainLoop;

Replies are listed 'Best First'.
Re: Re: Re: TK::Photo -file -data
by schimkat (Initiate) on Apr 18, 2002 at 13:10 UTC
    ... for visualizing what i meant with having the imagedata in a dbmopned hash, I have rewritten the example.

    First a script for creating the hash...
    #!/usr/bin/perl use GD; use Tk; use Tk::JPEG; use MIME::Base64; dbmopen %myhash, "myhash", 0666; my $im = GD::Image->new('image.jpg'); my $img = encode_base64($im->jpeg()); $myhash{image} = $img; dbmclose %myhash;


    ... and the a script for showing the image - using the imagedata in the hash:

    #!/usr/bin/perl use Tk; use Tk::JPEG; dbmopen %myhash, "myhash", 0666; my $main = MainWindow->new(); my $image = $main->Photo("button", -data => $myhash{image}, -format => + 'jpeg'); my $label= $main->Label(-image => "button"); $label->grid(-in => $main); dbmclose %myhash; MainLoop;


    One of the great things is the compression:
    My image.jpg is 14.9 Kb.
    When compressed it is 13.4 Kb.
    When compressing the hash containing the imagedata - it's only 7.7 Kb.

    That's cool.

    Søren Schimkat
      Now it works with GIF's. :-)
      Just use GD ver. 1.19 instead of 1.38 which is the current release.

      Script for creating hash:
      #!/usr/bin/perl use GD; use Tk; use MIME::Base64; dbmopen %myhash, "myhash", 0666; open (GIF,"image.gif"); $im = newFromGif GD::Image(GIF); close GIF; my $img = encode_base64($im->gif); $myhash{image} = $img; dbmclose %myhash;

      And a script for showing the image:
      #!/usr/bin/perl use Tk; dbmopen %myhash, "myhash", 0666; my $main = MainWindow->new(); my $image = $main->Photo("button", -data => $myhash{image}, -format => + 'gif'); my $label= $main->Label(-image => "button"); $label->grid(-in => $main); dbmclose %myhash; MainLoop;


      Regards Søren Schimkat
        ... and finally... a real life script: CatanAid

        I have dropped the hash and replaced it with a plain text file for better compatibillity with different platforms.

        Regards Søren Schimkat