note 101286 deleted from function.imagecolorallocate by danbrown
| From: | danbrown@php.net | Date: | Wed, 08 Dec 2010 14:19:49 +0000 |
| Subject: | note 101286 deleted from function.imagecolorallocate by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-174706@lists.php.net to get a copy of this message | ||
Note Submitter: kbolino at sdf dot lonestar dot org
----
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
?>