該功能是用戶上傳圖片時,程序會生成一個新的白色背景的squre圖片,並將用戶的圖片放在該圖片的中心。使用php生成圖片,背景總是顏色錯誤
但問題是,我將背景設置爲白色,它總是顯示黑色。
的代碼是
$capture = imagecreatetruecolor($width, $height);
$rgb = explode(",", $this->background);
$white = imagecolorallocate($capture, $rgb[0], $rgb[1], $rgb[2]);
imagefill($capture, 0, 0, $white);
和控制顏色的代碼是 protected $background = "255,255,255";
我一直在試圖改變$white = imagecolorallocate($capture, $rgb[0], $rgb[1], $rgb[2]);
到$white = imagecolorallocate($capture, 255, 255, 255);
。但背景仍然以黑色顯示。
感謝您的任何答案
「不工作」是什麼意思?背景顏色是什麼?另外,你如何渲染圖像? –
@Zach Rattner它仍然以黑色而不是白色顯示。我使用imagejpeg來渲染圖像 – Juni
'''header('Content-Type:image/jpeg'); $ im = @imagecreatetruecolor(120,20) or die('Can not Initialize new GD image stream'); $ rgb = explode(「,」,「255,255,255」); $ white = imagecolorallocate($ im,$ rgb [0],$ rgb [1],$ rgb [2]); imagefill($ im,0,0,$ white); imagejpeg($ im);'''適合我,你確定你以後不會覆蓋它嗎? – Deebster