I looked up dozens of entries from google and lots of docs on Tk and GD. All of the examples show how to save images to a file, which, no surprise works! But none show how to move data from the GD format (jpeg is fine) to a Tk::Label widget...frustrating because it has to be very easy...


use Tk; use Tk::JPEG; use GD::Graph::lines3d; use strict; my $mw = new MainWindow; my @data = ( ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], [ 1203, 3500, 3973, 2859, 3012, 3423, 1230] ); my $graph = new GD::Graph::lines3d(100, 100); $graph->set( x_label => 'Day', y_label => 'Hits', title => 'Summary', ); my $gd = $graph->plot(\@data); # Works my $a = $mw->Photo('img1', -format=>'JPEG', -file=>"test.jpg"); # Doesn't work (couldn't recognize image data) #my $b = $mw->Photo('img2', -format=>'JPEG', -data=>$gd->jpeg); # Works - writes image to file (and it is the graph!) open(IMG, '>abc123.jpeg') or die $!; binmode IMG; print IMG $gd->jpeg; close(IMG); # Doesn't work, (couldn't recognize image data) #$mw->Label(-image=>$gd->jpeg) # ->pack(-fill=>'both'); # Works $mw->Label(-image=>'img1') ->pack(-fill=>'both'); MainLoop;
I know it is my fault, but it seems that I have asked for a JPEG format and then passed a JPEG format ??? Is this what they call "weak typing"?

The $gd->jpeg has a value starting with:
ÿØÿà..JFIF..........ÿþ.>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality\n" (got it from the debugger)

thanks for any help !!!

Edit kudra, 2001-09-26 Added code tags


In reply to passing anything from GD to Tk ??? by smackdab

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.