php.net |  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
 [2011-01-15 16:05 UTC] mesmsgs at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.imagefilledellipse#Exemples
---

I can't change the background color

Test script:
---------------
<?php

// 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");
imagepng($image);

?>

Expected result:
----------------
The background color must be white

Actual result:
--------------
Only black background

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

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] ross@php.net
-Status: Assigned +Status: Bogus
 [2011-01-15 17:03 UTC] ross@php.net
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);

Regards
 [2011-01-16 01:52 UTC] kalle@php.net
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] kalle@php.net
-Type: Bug +Type: Documentation Problem
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 16:01:29 2024 UTC