note 101286 modified in function.imagecolorallocate by thiago
| From: | thiago@php.net | Date: | Wed, 08 Dec 2010 14:06:38 +0000 |
| Subject: | note 101286 modified in function.imagecolorallocate by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-174705@lists.php.net to get a copy of this message | ||
imagecolorallocate returns an RGB hex value (and thus can be bypassed) only if the image in question
is a 32-bit color image (as created by imagecreatetruecolor). If the image is a palette-based image
(as created by imagecreate), then you must use imagecolorallocate, which in this case returns a
palette index number and not an RGB hex value.
Code example, for a 32-bit color image:
<?php
$im = imagecreatetruecolor(100, 100);
$white = imagecolorallocate($im, 255, 255, 255);
// now $white == 0xFFFFFF
?>
Code example, for a palette-based image:
<?php
$im = imagecreate(100, 100);
$white = imagecolorallocate($im, 255, 255, 255);
// now $white == index of color #FFFFFF in palette
?>
--was--
To amend what oni-kun[at]oni-kun[dot]com said, imagecolorallocate returns an RGB hex value (and thus
can be bypassed) only if the image in question is a 32-bit color image (as created by
imagecreatetruecolor). If the image is a palette-based image (as created by imagecreate), then you
must use imagecolorallocate, which in this case returns a palette index number and not an RGB hex
value.
Code example, for a 32-bit color image:
<?php
$im = imagecreatetruecolor(100, 100);
$white = imagecolorallocate($im, 255, 255, 255);
// now $white == 0xFFFFFF
?>
Code example, for a palette-based image:
<?php
$im = imagecreate(100, 100);
$white = imagecolorallocate($im, 255, 255, 255);
// now $white == index of color #FFFFFF in palette
?>
http://php.net/manual/en/function.imagecolorallocate.php