You're including a load of HTML (I'm guessing in an included file?) and then calling imageJPEG().
When you make a dynamic jpeg you should have a script that does:
//Stuff to make the jpeg
header("Content-type: image/jpeg");
imageJPEG($jpeg);
Nothing else. You cannot create images in the middle of an HTML page. Doesn't work.