我目前正在從base64 png創建一個圖像,然後合併另一個PNG。我的代碼如下,但temp.png僅僅是空的,即使$文件名的輸出仍然是原來的圖像:PHP GD圖像不合並
session_start();
$email = $_SESSION['email'];
$img = $_POST['img'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$fileData = base64_decode($img);
$fileName = "./gallery/" . bin2hex(openssl_random_pseudo_bytes(16)) . ".png";
file_put_contents($fileName, $fileData);
//Merge Two Images
header ("Content-type: image/png");
$background = imagecreatefrompng($fileName);
$pkt = imagecreatefrompng("./frames/frame1.png");
$insert_x = imagesx($pkt);
$insert_y = imagesy($pkt);
imagecopymerge($background,$pkt,0,0,0,0,$insert_x,$insert_y,100);
imagepng($background,"temp.png",100);
也許關於你的png透明度。檢查[這個問題](http://stackoverflow.com/questions/5529306/i-cant-use-transparent-background-with-imagecopymerge) – cwps