I\'m using a solution for assembling image files to a zip and streaming it to browser/Flex application. (ZipStream by Paul Duncan, http://pablotron.org/software/zipstream-ph
One way is to tell GD to output the image, then use PHP buffering to capture it to a string:
$imagedata = imagecreatefrompng($imagefile); ob_start(); imagepng($imagedata); $stringdata = ob_get_contents(); // read from buffer ob_end_clean(); // delete buffer $zdata = gzdeflate($stringdata);