|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #53757 can't change the background
Submitted: 2011-01-15 16:05 UTC Modified: 2011-01-16 01:52 UTC
From: mesmsgs at gmail dot com Assigned: ross (profile)
Status: Not a bug Package: Documentation problem
PHP Version: 5.2.17 OS: Windows 7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: mesmsgs at gmail dot com
New email:
PHP Version: OS:


 [2011-01-15 16:05 UTC] mesmsgs at gmail dot com
From manual page:

I can't change the background color

Test script:

// create a blank image
$image = imagecreatetruecolor(400, 300);

// fill the background color
$bg = imagecolorallocate($image, 255, 255, 255);

// choose a color for the ellipse
$col_ellipse = imagecolorallocate($image, 0, 0, 0);

// draw the white ellipse
imagefilledellipse($image, 200, 150, 300, 200, $col_ellipse);

// output the picture
header("Content-type: image/png");


Expected result:
The background color must be white

Actual result:
Only black background


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-15 16:33 UTC]
-Status: Open +Status: Assigned -Package: Website problem +Package: Documentation problem -Assigned To: +Assigned To: ross
 [2011-01-15 16:33 UTC]

You are correct, the example is wrong as imagecolorallocate only sets the 
background colour on palette-based images (imagecreatetruecolor should be 
imagecreate). I'll fix the example.
 [2011-01-15 17:03 UTC]
-Status: Assigned +Status: Bogus
 [2011-01-15 17:03 UTC]
After some confusion (thinking you included the original example in your report) 
it turns out the example is not wrong. In future, please don't submit help 
requests as bug reports, try the php.general mailing list, an IRC channel or a 
support site such as StackOverflow.

As for your query, try adding this line underneath where you set $bg: 
imagefill($image, 0, 0, $bg);

 [2011-01-16 01:52 UTC]
To be more verbose why this is not working;

it works with imagecreate() based instances because it returns a palette based image, whereas with imagecreatetruecolor() that is not the case.

The first color allocated in a palette based image will always change the background color (unless overwritten). Where in true color based images (that defaults to a black background) you must create a rectangle to overlay the image to change the background.
 [2011-01-16 01:52 UTC]
-Type: Bug +Type: Documentation Problem
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Dec 03 08:01:23 2020 UTC