Recommendation for color-representation in PEAR-packages
| From: | Stefan Neufeind | Date: | Tue, 17 Feb 2004 15:56:30 +0000 |
| Subject: | Recommendation for color-representation in PEAR-packages | ||
| Groups: | php.pear.qa | ||
| Request: | Send a blank email to pear-qa+get-573@lists.php.net to get a copy of this message | ||
Following my previous mail and the discussions we lately already had
on pear-dev about a common scheme for color-representation in PEAR-
packages I've written a text for the new recommendations-section of
the PEAR-manual. Please note that the points mentioned in this text
have already been discussed throughly and were agreed upon.
Regards,
Stefan
Color-representation inside PEAR-packages
We recommend that developers store and use an array-representation of
color-values in their PEAR-packages. All values are in the range of
0..255.
* RGB-presesentation *
An example using our "PEAR-green" would look like:
$color = array(0x33, 0x99, 0x00);
or
$color = array(51, 153, 0);
Please note that the internal, numerical representation of both forms
of the example are equal. The values represent the RGB (red, green,
blue) values. It was decided not to use "r", "g" and "b" and indizes
for the array because allows for easier creation of color-arrays in
sourcecode, makes handling less complicated and is an already
commonly used array-representations for colors.
* RGB-representation with alpha-values *
Since this an extension of the RGB-representation above it's
recommended to use a forth value for alpha-channel-prepresentation.
An example of our pear-color with our "PEAR-green" with aprox. 80%
intensity would be:
$color = array(0x33, 0x99, 0x00, 0xCC);
For consistency the alpha-value is also from the range 0..255. A
value of 255 means fully opaque (full color-intensity, same as in RGB-
notation), 0 means fully transparent.
Please note this is in contrast to the alpha-value used by
imagecolorallocate(). Our alpha-representation was choosen for
consistency with the other RGB-values and because it's commonly
accepted practise in many other applications (image-processing tools,
...).
* Other color-representations than RGB(A) *
Since RGB/RGBA will used for graphic generation on a computer we
decided to leave out an optional type-identifier classifying colors
as RGB/RGBA. However for different color-representations an
identifier is needed. The optional identifier "type" can be added to
the color array. Example:
$color = array(0x33, 0x99, 0x00, 0xCC, "type" => "RGB");
Currently the following types are definied, with array-indices from
0..n follwing the colornames in the table:
type: colornames:
RGB red, green, blue
CYMK cyan, yellow, magenta, black (key)
Please note that also the RGBA-representation has the type "RGB"
since it's closely related.
* Conversion to/between the color-representations *
The PEAR-package <a href="...">Image_Color</a> will (hopefully soon)
contain all needed functions to convert arbitrary color-formats to
the internal RGBA-representation and convert different color-
representations.
Status: Currently Image_Color already offers functions to convert
color-names (e.g. "green") and hex-representations-strings (e.g.
"#339900") to the PEAR-RGBA-format. We are working to get alpha-
channel support added hopefully soon and will later add funtions for
CYMK-conversion as well.