2014-04-18 192 views
0

我正在使用下面的代碼來調整圖像大小。當透明圖像(png/gif)被上傳時,所創建的新圖像具有黑色背景。如何在調整大小後使背景變成白色?請幫助在代碼中使用PHP - 調整大小後的黑色背景透明png和gif

imagecolortransparent 

$info = pathinfo($_FILES['file']['name']); 
    $ext = $info['extension']; // get the extension of the file 
    $newname = "testing".".".$ext; 
    $target = 'uploads/'.$newname; 
    move_uploaded_file($_FILES['file']['tmp_name'], $target);; 
    $filename=$newname; 
    if($ext=='jpg'||$ext=='jpeg') 
    { 
     $im = imagecreatefromjpeg('uploads/'.$filename); 
    } 
    else if ($ext=='gif') 
    { 
     $im = imagecreatefromgif('uploads/'.$filename); 
    } 
    else if ($ext=='png') 
    { 
     $im = imagecreatefrompng('uploads/'.$filename); 
    } 
    $ox = imagesx($im); 
    $oy = imagesy($im); 
    $nm = imagecreatetruecolor(245, 184); 
    imagealphablending($nm, FALSE); 
    imagesavealpha($nm, TRUE); 
    imagecopyresized($nm, $im, 0,0,0,0,245,184,$ox,$oy); 
    imagejpeg($nm, 'uploads/' . $filename); 
+0

嘗試在白色背景上繪製圖像,然後另存爲JPG。 – Overv

+0

它是如何做到的?任何功能? –

+0

@Overv如何做到這一點? –

回答