我使用此代碼來將png圖像添加爲上傳圖像的水印,但結果不是圖像,也不想使用header()我希望代碼繼續執行其他的PHP查詢,而無需導航到另一個頁面來顯示圖像。圖像獲得上傳,但沒有水印和標題()沒有發佈任何圖像只是一個灰色小方塊在上傳的圖像中添加水印圖像
$path = "../large/";
$num = substr(md5(mt_rand(1,9999999999)),0,9);
$new_name = $path.$num.".jpg";
$image = $num.".jpg";
move_uploaded_file($img_tmpname,$new_name);
$image = imagecreatefromjpeg($new_name);
$logoImage = imagecreatefrompng("images/watermark.png");
imagealphablending($logoImage, true);
$imageWidth=imagesx($image);
$imageHeight=imagesy($image);
$logoWidth=imagesx($logoImage);
$logoHeight=imagesy($logoImage);
imagecopy(
// destination
$image,
// source
$logoImage,
// destination x and y
$imageWidth-$logoWidth, $imageHeight-$logoHeight,
// source x and y
0, 0,
// width and height of the area of the source to copy
$logoWidth, $logoHeight);
// Set type of image and send the output
header("Content-type: image/png");
imagePng($image);
// Release memory
imageDestroy($image);
imageDestroy($imageLogo);
'imagePng'應該是'imagepng'和'imageDestroy'應該是'imagedestroy' – RamRaider
相同的結果 –
路徑'圖像/ watermark.png'〜首先請問文件存在於該位置,其次有你嘗試使用該圖像的完整路徑? – RamRaider