Skip to content

Instantly share code, notes, and snippets.

@mojeld
Created July 24, 2018 04:38
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 mojeld/c70e9eed025f6725230fad8cb66e5265 to your computer and use it in GitHub Desktop.
Save mojeld/c70e9eed025f6725230fad8cb66e5265 to your computer and use it in GitHub Desktop.
PowerShell Color文字列 #000000をRGB分割してint型に変換表示
<#
2018.07.24
PowerShell 色文字(#000000)からRGB分けてint変換
セキュリティがかかっている場合はSet-ExecutionPolicy RemoteSigned https://go.microsoft.com/fwlink/?LinkID=135170 を管理者モードで試す
PowerShellで rgb.ps1を実行した後、 > str_to_rgb -color "#00ff00"
#>
function global:str_to_rgb()
{
Param([string]$color)
$local:rgb = @("r","g","b");
for ($local:i = 0; $local:i -lt 3; $local:i++){
$local:l_ = $rgb[$local:i] + "=" + [Convert]::ToInt64($color.Substring($local:i*2+1, 2),16) + "; "
$local:o_ = $local:o_ + $local:l_
}
return $local:o_
}
<#
str_to_rgb -color "#00ff00"
#上記のように実行すると下記のように返す
#r=0; g=255; b=0;
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment