2013-08-23 35 views
4

時,我有幾個png圖片均產生像這樣認爲:PHP - 顏色不正確使用imagecopy的

$img = imagecreatefrompng($full_path_to_file); 
imagealphablending($img , true); // setting alpha blending on 
imagesavealpha($img , true); // save alphablending setting 

的圖像打印出來細末,用正確的顏色和透明背景。

我需要將這些圖像組合成一個。對於我做到以下幾點:

  1. 由一個到空白圖像

    imagecopy($full_image, $src, $dest_x, $dest_y, 0, 0, $src_width, $src_height

  2. 創建正確的尺寸

    $full_image = imagecreate($full_width, $full_height);

  3. 複製PNG圖像之一的空白圖像

圖像是c呃,好吧。背景是透明的,但是的顏色不正確。

我怎樣才能確保獲得正確的顏色?

更新:的建議,解決辦法是使用imagecreatetruecolor另外,我需要把第二個參數設置爲imagealphablending爲false。因此,創建PNG圖像和創建full_image時,我呼籲imagesavealpha says

imagealphablending($img , false); // updated to FALSE 
imagesavealpha($img , true); 

文件:向未設置alphablending(imagealphablending($ IM,FALSE))

你,要 使用它。

+0

你能告訴我們你的意思是「不正確」嗎? –

+0

你使用你沒有CMYK文件?你不會是第一個 – Martijn

回答

2

嘗試使用:imagecreatetruecolor而不是imagecreate。

+0

試過它。沒有做任何事情。 imagecreatetruecolor是爲jpegs –

+1

你試過imagecopymerge這兩個PNG到創建imagecreatetruecolor和輸出與imagepng? – stu236

+0

一秒鐘。我實際上再次嘗試'imagecreatetruecolor',這次它給了我正確的顏色,但是背景是黑色而不是透明的 –

0

只需要後稱爲

$白色= imagecolorallocate($ destination_image,255,255,255)imagecopy的()方法添加以下代碼; imagefill($ destination_image,0,0,$ white);

+1

你能解釋一下嗎? –