Se commenti la chiamata a header() e a imagejpeg() e richiami direttamente nel browser l'URL dello script che cosa ottieni?