2012-02-07 52 views
0

我想知道在使用PHP GD擴展在其他圖像上繪製圖像時是否可能產生「不透明」效果?有沒有任何內置的函數可以得到我想要的結果,或者我需要使用imagesetpixel的方法去實現自己的結果?使用PHP GD擴展的不透明效果

僞代碼來說明什麼,我想現在做的事:

// Background image 
$image_bg = imagecreatetruecolor(100, 100); 
imagesavealpha($image_bg, true); 

// Making background image fully transparent 
imagefill($image_bg, 0, 0, imagecolorallocatealpha($image_bg, 0, 0, 0, 127)); 

// Now the actual image I want to draw with opacity (true color PNG) 
$image = imagecreatefrompng(...); 

// Drawing with 50 "merge" value 
imagecopymerge($image_bg, $image, ..., 50); 

與上面的代碼的麻煩是,imagecopymerge不會尊重背景圖像alpha值,並且將圖像與背景融合如果它是不透明的黑色(產生的圖像不會是50%透明)。

編輯:我結束了使用imagecoloratimagesetpixel的方式實現我自己的功能。

回答

-1
+2

這並不能真正回答我的問題。這是一個盲目的鏡頭,因爲我沒有使背景或圖像透明的問題。 'imagealphablending'在默認情況下啓用了真彩色圖像,'imagecolortransparent'僅適用於具有單一透明顏色(例如GIF)的調色板樣式圖像。 – Sim 2012-02-07 12:27:44