Last active
October 5, 2018 03:09
-
-
Save mattmcnabb/20f4f7aec041801cdca9b01b065c321c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function ConvertFrom-RGB | |
{ | |
param | |
( | |
[Parameter(Mandatory)] | |
[ValidateCount(3,3)] | |
[Byte[]] | |
$RGB | |
) | |
$Hexes = foreach ($Byte in $RGB) | |
{ | |
[Convert]::ToString($Byte, 16).ToUpper() | |
} | |
"#{0}{1}{2}" -f $Hexes | |
} | |
function ConvertTo-Rgb | |
{ | |
param | |
( | |
[parameter(Mandatory)] | |
[ValidatePattern("^#[A-Fa-f0-9]{6}$")] | |
[string] | |
$Hex | |
) | |
$null = $Hex -match "^#(?'Byte1'\w{2})(?'Byte2'\w{2})(?'Byte3'\w{2})$" | |
$Matches.Byte1, $Matches.Byte2, $Matches.Byte3 | foreach { | |
[Convert]::ToByte($_, 16) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment