Try this. The functions work in a similar way.
imagepng: how to save the output in a variable and then display it using img tag
ob_start(); imagejpeg($image); $imagedata = ob_get_clean();