public static function getFadedColor($color, $percentage = 85) { $percentage = 100 - $percentage; $rgbValues = array_map('hexDec', str_split(ltrim($color, '#'), 2)); for ($i = 0, $len = count($rgbValues); $i < $len; $i++) { $rgbValues[$i] = decHex(floor($rgbValues[$i] + (255 - $rgbValues[$i]) * ($percentage / 100))); } return implode('', $rgbValues); }
function binary_to_hex($str) { $ret = ''; $c = strLen($str); for ($i = 0; $i < $c; ++$i) { if ($i !== 0) { $ret .= '-'; } $ret .= str_pad(decHex(ord(@$str[$i])), 2, '0', STR_PAD_LEFT); } return $ret; }
/** * public static function HSVToRGB * */ public static function HSVToRGB($color) { list($H, $S, $V) = array($color['H'] / 360, $color['S'] / 100, $color['V'] / 100); if ($S == 0) { $r = $V * 255; $g = $V * 255; $b = $V * 255; } else { $var_h = $H * 6; if ($var_h == 6) { $var_h = 0; //$H must be < 1 } $var_i = floor($var_h); $var_1 = $V * (1 - $S); $var_2 = $V * (1 - $S * ($var_h - $var_i)); $var_3 = $V * (1 - $S * (1 - ($var_h - $var_i))); if ($var_i == 0) { $var_r = $V; $var_g = $var_3; $var_b = $var_1; } elseif ($var_i == 1) { $var_r = $var_2; $var_g = $V; $var_b = $var_1; } elseif ($var_i == 2) { $var_r = $var_1; $var_g = $V; $var_b = $var_3; } elseif ($var_i == 3) { $var_r = $var_1; $var_g = $var_2; $var_b = $V; } elseif ($var_i == 4) { $var_r = $var_3; $var_g = $var_1; $var_b = $V; } else { $var_r = $V; $var_g = $var_1; $var_b = $var_2; } $r = $var_r * 255; $g = $var_g * 255; $b = $var_b * 255; } $rgb = decHex(intval($r)) . decHex(intval($g)) . decHex(intval($b)); return array('R' => intval($r), 'G' => intval($g), 'B' => intval($b), 'color' => $rgb); }
* Philipp Kempgen <*****@*****.**> * Peter Kozak <*****@*****.**> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. \*******************************************************************/ # converts a string to hex values separated by ":" for use in # dhcpd.conf if ($argc < 2) { echo "Specify a string!\n"; die(1); } $str = $argv[1]; $hex = array(); $l = strLen($str); for ($i = 0; $i < $l; ++$i) { $hex[] = str_pad(strToUpper(decHex(ord(subStr($str, $i, 1)))), 2, '0', STR_PAD_LEFT); } echo implode(':', $hex), "\n";
public static function asHex($val) { $_ = decHex($val); while (fMod(strLen($_), 4)) { // in 4-blocks $_ = '0' . $_; } return '0x' . strToUpper($_); }
public function getXML($index = -1, $deep = 0, $ClientFlags = 0) { $out = ''; //- Main run -// if ($index == -1 && $deep == 0 && $ClientFlags == 0) { //$out = "<'.'?xml version='1.0'?'.'>\n"; //$out .= "<!-- Filename='". htmlentities($this->m_lv->getFileName()) ."' -->\n\n"; $out .= "<VCTP>\n"; foreach ($this->m_objects as $i => $ob) { $out .= $this->getXML($i, 1); } $out .= $this->m_error->getXML(); $out .= "</VCTP>\n"; return $out; } //- Sub run --// if (!isset($this->m_objects[$index])) { return ''; } $SpPad = str_repeat(' ', $deep * 2); $ob =& $this->m_objects[$index]; switch ($ob['mainType']) { case self::MainTypeValue: $tagName = 'VALUE'; brak; default: $tagName = 'VAR'; break; } $out .= $SpPad . "<" . $tagName . " index='" . $index . "' "; if ($ob['type'] < 256 && $ob['type'] >= 0) { $out .= " ObjectType='0x" . decHex($ob['type']) . ":" . $ob['name'] . "' "; } else { if ($ob['name'] == '') { $out .= " ObjectType='0x" . decHex($ob['fileType']) . ":unknown' "; } else { $out .= " ObjectType='" . $ob['name'] . "' "; } } if ($ob['label'] != '') { $out .= " Label='" . htmlentities($ob['label']) . "' "; } if ($ClientFlags != 0) { if ($ClientFlags & 0x100) { $out .= "Type='input' "; $ClientFlags = $ClientFlags - 0x100; } else { $out .= "Type='output' "; } if ($ClientFlags > 0) { $out .= "TerminalFlag='0x" . decHex($ClientFlags) . "' "; } } foreach ($ob['atrib'] as $attribut) { $n = $attribut['n']; if (!isset($this->AttributNameTable[$n])) { $n = self::AttributTypeUnknown; } $out .= $this->AttributNameTable[$n] . "="; switch ($attribut['t']) { case self::DataTypeString: $out .= "'" . htmlentities($attribut['v']) . "' "; break; case self::DataTypeNumber: $out .= "'" . $attribut['v'] . "' "; break; case self::DataTypeNumberAsHex: $out .= "'0x" . decHex($attribut['v']) . "' "; break; default: $out .= "'0x" . decHex($attribut['v']) . ":" . htmlentities($attribut['v']) . "' "; break; } } if (count($ob['clients']) == 0) { $out .= "/>\n"; } else { $out .= ">\n"; foreach ($ob['clients'] as $client) { $out .= $this->getXML($client['index'], $deep + 1, $client['flags']); } $out .= $SpPad . "</" . $tagName . ">\n"; } return $out; // print_r($this->m_objects, true); }
function getFadedColor($pCol, $pPercentage = 85) { $pPercentage = 100 - $pPercentage; $rgbValues = array_map('hexDec', GCalendarUtil::str_split(ltrim($pCol, '#'), 2)); for ($i = 0, $len = count($rgbValues); $i < $len; $i++) { $rgbValues[$i] = decHex(floor($rgbValues[$i] + (255 - $rgbValues[$i]) * ($pPercentage / 100))); } return '#' . implode('', $rgbValues); }
/** * Returns the color in the CSS hexadecimal format, e.g. '#000000'. * @return string */ public function toHex() { return sprintf('#%02s%02s%02s', decHex($this->r), decHex($this->g), decHex($this->b)); }