Simply do this:
imagealphablending($img, false);
imagesavealpha($img, true);
Before outputting. Make sure that all source files (if you used any) are set to PNG 32-bit with transparency - if not the output may differ with black background or transparency does not comply.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…