in reply to Re: Which tk to use and how to show images?
in thread Which tk to use and how to show images?

I cannot verify this myself as I upgraded to 5.8.7 and I am still working through rebuilding everything else, and I haven't done GD yet. Shouldn't you be able to bypass the intermediate file by using the Tk::Photo -data option?

my $png = $mw->Photo( -format => 'png', -data => $gd->png );

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^3: Which tk to use and how to show images?
by rcseege (Pilgrim) on Nov 04, 2005 at 04:31 UTC
    Shouldn't you be able to bypass the intermediate file by using the Tk::Photo -data option?

    Well, I did bypass the intermediate file in the second example using the -data option, but I tried to use your snippet which looked shorter anyway. Unfortunately, it didn't work. I think I've tried this in the past, but hoped for a second that the internals had been modified when you mentioned it. For it to work, the data has to be base64 encoded, before it can be passed, otherwise Tk complains that it doesn't understand the format.

    I'd be interested if you have a way around this. I've only occasionally used GD, and I'm definitely not an expert with it.

    Rob
      For it to work, I had to make sure the data is base64 encoded ...

      Now you mention it, I think I had to go that route also. It was a while ago.

      That said, logic suggests that you should be able to bypass IO::String, and pass the output from gd directly to encode_base64():

      my $png = $mw->Photo(-data => encode_base64( $gd->png ));

      I see no reason that shouldn't work as what ends up in the file is exactly what comes out of the image methods, hence the need for binmode;

      I've made quite a lot of use of GD (though I hardly qualify as an expert), but I am light on Tk;

      (Grrr. I hate being unable to try stuff, and I hate the available upgrade paths for perl.)


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        I see no reason that shouldn't work as what ends up in the file is exactly what comes out of the image methods, hence the need for binmode;

        You're absolutely right -- it worked fine. Thanks for that! I've corrected the example to remove it.