Skip to content

Instantly share code, notes, and snippets.

@sbarrat
Last active December 19, 2015 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbarrat/5908351 to your computer and use it in GitHub Desktop.
Save sbarrat/5908351 to your computer and use it in GitHub Desktop.
Function to change vba color to hex or rgb
/**
* vbaColorToWeb.php Class to convert VBA color to web Color
*
*
* PHP Version 5.3
*
* @author Ruben Lacasa Mas <ruben@rubenlacasa.es>
* @copyright 2013 Ruben Lacasa Mas http://rubenlacasa.es
* @license http://creativecommons.org/licenses/by-nc-nd/3.0
* CC-BY-NC-ND-3.0
* @link https://gist.github.com/sbarrat/5908351
*/
/**
* @param $color Color vba
* @param bool $hex if $hex is true return hex value if not return rgb value
* @return string
*/
function vbaColorToWeb($color, $hex = false)
{
$red = $color % 256;
$green = ($color / 256) % 256;
$blue = ($color / 256 / 256) % 256;
if ($hex) {
return "#".dechex($red).dechex($green).dechex($blue);
} else {
return "rgb(".$red.", ".$green.", ".$blue.")";
}
}
// Example
$color = 8429680;
echo vbaColorToWeb($color); // Shows rbg(112, 160, 128)
echo vbaColorToWeb($color, true); // Shows #70a080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment