To 1)
imagecreatefrompng('test.png')
tries to open the file test.png
which then can be edited with GD functions.
To 2)
To enable saving of the alpha channel imagesavealpha($img, true);
is used.
The following code creates a 200x200px sized transparent image by enabling alpha saving and filling it with transparency.
<?php
$img = imagecreatetruecolor(200, 200);
imagesavealpha($img, true);
$color = imagecolorallocatealpha($img, 0, 0, 0, 127);
imagefill($img, 0, 0, $color);
imagepng($img, 'test.png');