Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: TK::Photo -file -data

by clintp (Curate)
on Apr 17, 2002 at 14:29 UTC ( #159825=note: print w/ replies, xml ) Need Help??


in reply to TK::Photo -file -data

If you use -data, I believe the -format option is required.


Comment on Re: TK::Photo -file -data
Re: Re: TK::Photo -file -data
by schimkat (Initiate) on Apr 18, 2002 at 06:40 UTC
    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;
      ... 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://159825]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2014-12-28 13:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (181 votes), past polls