Last active
December 19, 2015 05:59
-
-
Save sbarrat/5908351 to your computer and use it in GitHub Desktop.
Function to change vba color to hex or rgb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* vbaColorToWeb.php Class to convert VBA color to web Color | |
* | |
* | |
* PHP Version 5.3 | |
* | |
* @author Ruben Lacasa Mas <[email protected]> | |
* @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