Skip to content

Instantly share code, notes, and snippets.

@sbarrat

sbarrat/vbaColorToWeb.php

Last active Dec 19, 2015
Embed
What would you like to do?
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