ID:               21834
 User updated by:  [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
 Status:           Open
 Bug Type:         Documentation problem
 Operating System: Win2k
 PHP Version:      4.3.0
 New Comment:

I am only able to test JPG and PNG with my setup.

I suspect that what's happening is quite straightforward - when you
first create an instance of an image with imagecreate, it builds a
blank palette.  Each time you call imagecolorallocate(), it adds an
index to the palette with the specified colour.  So, you could think of
color allocation as

 $im->palette[] = array($r,$g,$b,$a); // a for alpha

As it just so happens, paletted images assume that palette index zero
($palette[0]) is actually the background colour.

I've been extracting the palette into a useful form using this code:

 $cols = imagecolorstotal($im);
 for($i=0;$i<$cols;$i++){
  $palette[$i] = imagecolorsforindex($im,$i);
 }

And running different sequences of colour allocations, then checking
the contents of $palette to see the results.

If you use imagecolorset() with the index 0, even after allocating
multiple colours, the background colour changes to whatever you
specify.

Got an unexpected result testing out imagecreatefrompng().  I opened a
png file of mine, and imagecolorstotal() came up 0.  Curious.  There
are certainly multiple colours within the image.  Perhaps it just
doesn't have a palette saved with it (does that make it a true colour
image?)

That's all I have for you atm.  More later as I discover it.


Previous Comments:
------------------------------------------------------------------------

[2003-01-22 23:15:08] [EMAIL PROTECTED]

Sure thing.  Later today I'll investigate different image types, and
post the results here.

I'll also see if things are different with imagecreatetruecolor() (I
suspect they will be).

------------------------------------------------------------------------

[2003-01-22 23:09:28] [EMAIL PROTECTED]

This will need some study and confirmation.  For example here is one
user comment:

"With gd 2.x, the first color allocated with imagecolorallocate()
appears to no longer be made the background color. You can use
imagefill() to set the background color."

Granted whatever behavior exists needs to be documented ... but what is
the exact behavior?  Please report further findings in this bug report
:)

------------------------------------------------------------------------

[2003-01-22 22:58:54] [EMAIL PROTECTED]

I discovered from experimentation that the first call to
imagecolorallocate() for a given image, sets the background colour for
that image.

This would be worth noting in the manual page for imagecolorallocate().
 Someone has pointed it out in a user comment, but it is a fairly
important aspect of the function's behaviour, and IMO should be part of
the official documentation.

I'm using php_gd2 as bundled with PHP 4.3.0, and I've only tried PNG
images so far.  I can't say for sure if imagecolorallocate() exhibits
this same behaviour for other image types.

As an aside, the GD functionality is great.  I'm loving the idea of
creating dynamic images in my app.

May the Force be with you.

------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=21834&edit=1


-- 
PHP Documentation Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to