http://www.perlmonks.org?node_id=423686


in reply to GD graphs and CGI

It is also important to change you output type to
# make sure we are writing to a binary stream binmode STDOUT;
So, when sending the correct header to the browser it will look like an image.
I had the same problem when dealing with images for the web. I found easier to put the script that generates
the graphic in a diferent page, staying like this
<img src='/perl/mygraph.pl'>