Try this:
http://www.cnovak.com
He made a script for bargraphs. You can download the code and take a look. It's quite simple, and it shows how to use headers for images.
But, if what you want is the easy way, this is the header for JPG
header("Content-type: image/jpeg");
Hope it helps
fLIPIS