If you have this problem, try to delete any space character between the begin of the script and the php tag
>
I spent several hours before realize this. And now it works OK. This happens because any character on the file alter the png format. This worked great for me.