note 96798 deleted from function.imagecolorallocate by thiago
| From: | thiago@php.net | Date: | Tue, 16 Mar 2010 19:10:01 +0000 |
| Subject: | note 96798 deleted from function.imagecolorallocate by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-167105@lists.php.net to get a copy of this message | ||
Note Submitter: yettycz at gmail dot com
----
Two useful functions for converting color from imageColorAllocate.
<?php
/**
* Convert color from imageColorAllocate() to hex in XXXXXX (eg. FFFFFF, 000000, FF0000)
*
* name: color2rgb
* author: Yetty
* @param $color value from imageColorAllocate()
* @return string; color in style XXXXXX (eg. FFFFFF, 000000, FF0000)
*/
function color2rgb($color) {
return str_pad(base_convert($color, 10, 16), 6, 0, STR_PAD_LEFT);
}
/**
* Convert color from hex in XXXXXX (eg. FFFFFF, 000000, FF0000) to array(R, G, B)
* of integers (0-255).
*
* name: rgb2array
* author: Yetty
* @param $color hex in XXXXXX (eg. FFFFFF, 000000, FF0000)
* @return string; array(R, G, B) of integers (0-255)
*/
function rgb2array($rgb) {
return array(
base_convert(substr($rgb, 0, 2), 10, 16),
base_convert(substr($rgb, 2, 2), 10, 16),
base_convert(substr($rgb, 4, 2), 10, 16),
);
}
?>