2013-07-18 39 views
0

我需要改變ImageCreateTrueColor白色背景的顏色,然後把圖像放在它更改背景顏色與PHP

elseif(($height>50)&&($width<50)) 
{ 
    $img_r = imagecreatefromjpeg($new_img_path); 
    $source = ImageCreateTrueColor(50, 50); 
    imagetruecolortopalette($source, FALSE, 2); 
    $bg = imagecolorat($source, 0, 0);   
    imagecolorset($source, $bg, 0, 0, 255); 
    // $white = imagecolorallocate($source,255,255,255); 
    // imagefilledrectangle($source, 0, 0, 50, 50, $white); 

    imagecopy($source, $img_r,0,0,0,0,$width,50); 
    header('Content-type: image/jpeg'); 
    imagejpeg($source, $small_new_img_path); 

這裏是藍色的,但它並不重要,它不會把圖像放在藍色背景上

+0

圖像應該是透明的背景可見 – DevZer0

+0

@ DevZer0我該怎麼做?你能告訴我嗎? – user2586329

+1

您需要使用.png圖片。 Jpeg格式不支持Alpha透明度(實際上,根本不透明)。堅持與PNG,你應該沒問題 – Andreyco

回答

1

你想創建一個PNG而不是JPEG。使用imagepngimagesavealpha

參見full example