BarryHall (1) [Avatar] Offline
#1
I have used your book to learn how to create simple diagrams and write them to a graphics file in png format, but I am unable to see how to display those same graphics on the screen (other than opening the file in a drawing program).

I am a fairly inexperienced Perl programmer, with no previous experience with graphics programming. I use Macintosh OSX, and programs are executed within the context of Mac Terminal program.

Using GD I can crete a graphic with no problem. I then open an output file and attempt to write the graphic both to the output file and to STDOUT as shown below:
#open a file for writing
unless(open(IMAGEFILE, '>Example.png')) {die "Cannot open the image file.
";}

# make sure we are writing to a binary stream
binmode STDOUT;
binmode IMAGEFILE;

# Convert the image to PNG and print it on standard output
print $im->png,"
";
print IMAGEFILE $im->png,"
";

The image file is written exactly as expeced, but my erminal window (SGTDOUT) displays:
?PNG

IHDR??(q?;PLTE???d}}??smilieͧtRNS@??f}IDATx??a??
F{?u?"`;r?3?V? 3?ݶ_~?
M__???to!??۽????[????~[C????V?U?RCf???iu?$wY??V?????V??_?U?X+??Ԑگ?m?$^>?c?d?y??;?8?
????=Ϭ???
?????*???E3???!?7???y
ߑ˸d?ęl*?u?
2?l|?????Uj]?>?k?2???j ?/+???X?ߖjb??`?$?PdJO?@?L??K??
????<Ħ/?"+.?f?(??f?w?) @>smilie??G?R?@?????t??V$,????xd?m-Y$ڎr?U?7?2??? B?ݸ?6?t?O??@?? ???|3???
9?????D??*??)HN?????????5bSd??rdh"????????Xa?f?T?ɚ?_q???4??????H ?H ?H i?/?????e8???!{**??)f???Jz?3??#H??y?_~4??2?HRq?," =?h?D??+?OH??L itD???~E$W?-iV?]???ݑfW??DP?f? ??o3Ol???f?7?i??~m66["?͝?6?f?ݙsmilieC?#???=???ʀH ?H ?H.??????k??E?IEND?B`?

Although writing to files is useful, it would be nice for the user to be able to see the output on screen. I assume that I need to direct the output to some graphics window that I open, but I have no idea where to start. Any thoughts?

Thanks for you help

Barry Hall