prova a passare il filename ad imagepng oppure a mettere "":

imagepng($immagine,"test.png");
imagepng($immagine,"");