RE: [PHP] Convert a grayscale value to a #RRGGBB hex value

From: Date: Mon, 24 Jun 2002 17:16:17 +0000
Subject: RE: [PHP] Convert a grayscale value to a #RRGGBB hex value
Groups: php.general 
Request: Send a blank email to php-general+get-103627@lists.php.net to get a copy of this message
I have an idea on how to do this. Could someone confirm whether this is a good approach? function grayscaletohex ($val) { $n = ($val * 255) / 100; // convert from range of 100 to range of 255 $h = dechex($n); // convert decimal to hex $results = $h.$h.$h; // create 6 digit browser color string return $results; } > -----Original Message----- > From: René Fournier [mailto:rene@smartslitters.com] > Sent: Sunday, June 23, 2002 12:52 PM > To: php-general@lists.php.net > Subject: [PHP] Convert a grayscale value to a #RRGGBB hex value > > > Anyone know how I might convert a grayscale value, from between 0 to > 100, to hex, such that 0 (black) would be returned as > #000000, and 100 > (white) as #FFFFFF? For example... > > function grayscaletohex ($val) { > $hex = $val ... [ a simple operation ] > return $hex; > } > > Thanks. > > ...Rene > > --- > René Fournier, > rene@smartslitters.com > > Toll-free +1.888.886.2754 > Tel +1.403.291.3601 > Fax +1.403.250.5228 > www.smartslitters.com > > SmartSlitters International > #33, 1339 - 40th Ave NE > Calgary AB T2E 8N6 > Canada > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > **************************************************************************** This message is intended for the sole use of the individual and entity to whom it is addressed, and may contain information that is privileged, confidential and exempt from disclosure under applicable law. If you are not the intended addressee, nor authorized to receive for the intended addressee, you are hereby notified that you may not use, copy, disclose or distribute to anyone the message or any information contained in the message. If you have received this message in error, please immediately advise the sender by reply email and delete the message. Thank you very much.

« previous php.general (#103627) next »