LD SoftwareBespoke Software, Web Design, Security Consultants and Host Services.

Menu

Sentinel
You have been warned!
We have caught 5883 shameful hackers.

NukeSentinel(tm)

Paypal Referral
Sign up for PayPal and start accepting credit card payments instantly.

Link Exchange
Join our free link exchange

Click Here
 
Color Representation inside PEAR Packages

Color Representation inside PEAR Packages

In case a package has to deal with colors, it is recommended that developers store and use an array representation of the color values in their PEAR packages. All values are in the range of 0..255.

RGB represesentation

The following snippet defines an array that holds the RGB definition of the green coloring that is used in the official PEAR logo.

$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" as indices for the array, because numerical indices allow easier creation of color arrays in the sourcecode, make handling less complicated and are an already commonly used array representation for colors.

RGB representation with alpha-values

Since this an extension of the RGB representation above, it is recommended to use a forth value for alpha-channel-prepresentation. An example of the "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(). The alpha-representation used in PEAR was choosen for consistency with the other RGB values and because it is commonly accepted practise in many other applications (image-processing tools, etc.).

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.

$color = array(0x33, 0x99, 0x00, 0xCC, "type" => "RGB");
Currently the following types are definied, with array-indices from 0..n follwing the colornames listed behind them:
  • 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 Image_Color 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.

 

Text Ads
There isn't content right now for this block.

Community Login
Welcome,
Anonymous

Nickname
Password
   

People Online:
Visitors: 116
Members: 1
Total: 117

Online Now:
01 : Monty

Like my code
Then please make a donation.

Which help me produce more free code.


Paypal Verified

Information

Powered by PHP-Nuke

Valid CSS!


Valid Robots.txt

Bad Behavior

[Valid RSS]

[Valid RSS]
You can syndicate our News with backend.php And our Forums with rss.php
You can also access our feeds via Feedburner Site News and LD Software Forums
© 2009 ld-software.co.uk All Rights Reserved.
PHP-Nuke Copyright © 2005 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.49 Seconds