Maybe the result is getting truncated? Try wget or curl to fetch the file directly and cmp it to the original image; that should help debug it. Beyond that, post your full code and environment details even if it's simple.
Ken Arnold
2009-06-09 02:28:37