Your image tag will, when you render it,
src="<<a whole bunch of binary
Why? because your
function emits the image inline using the
single-parameter form of
Instead, you need to emit the image to a .png
file, then mention that file's name in your
<img ... /> tag.
You could change the last few lines of your
function to work like this.
$file = "tmp-" . rand() . ".png";
return "/" . $file;
This will make your function create a png file
with a random name and then return the path to
that file to be used in your
This will take some debugging. The way I have
written it, it assumes that you are able to write
to the current working directory. You probably
need to write to some temp directory that's
accessible to your web server instead.
Also, these image files will pile up. You'll
need to cook up some cron job or something to
clean out the old ones.