2015-01-06 105 views
0

我合併了兩個圖像。第一張圖片將始終爲白色,擴展名爲PNG,大小爲1200像素x 628像素。第二張圖片的尺寸是1000px X 495px。但是,當我合併圖像,然後將白色圖像轉換成黑色圖像。並顯示第二張圖像的背景爲黑色。 請幫助我如何解決這個問題,並將黑色圖像變成白色圖像。PHP合併圖像

+0

對不起請你附上你得到的和你想要輸出的東西。 –

+0

哪個庫使用'GD2'或'ImageMagick'顯示你的代碼? – Girish

+0

請同時向我們展示您的當前代碼,否則我們不能幫您 –

回答

0

添加以下行代碼,您的問題應該得到解決,

imagealphablending($new_image, false); 
imagesavealpha($new_image, true); 
$transparent = imagecolorallocatealpha($new_image, 255, 255, 255, 127); 
imagefilledrectangle($new_image, 0, 0, $width, $height, $transparent); 

僅供參考,用於調整圖像大小的全部源代碼,

function resize($width,$height) { 
     $new_image = imagecreatetruecolor($width, $height); 
     if ($this->image_type == IMAGETYPE_PNG){ 
     imagealphablending($new_image, false); 
     imagesavealpha($new_image, true); 
     $transparent = imagecolorallocatealpha($new_image, 255, 255, 255, 127); 
     imagefilledrectangle($new_image, 0, 0, $width, $height, $transparent); 
     } 
     imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); 
     $this->image = $new_image; 
    }  
+0

如何決定OP是否使用GD2進行圖像處理? – Girish

+0

對不起,Girish我可能不會回答你的問題,但上面代碼中使用的函數僅適用於GD。 http://php.net/manual/en/ref.image.php – jaym

+0

你的答案是正確的,但是'op'還沒有顯示出代碼在哪個庫中使用,如果他使用'ImageMagick',那麼這個代碼可以工作? – Girish