Skip to content

Instantly share code, notes, and snippets.

@StartAutomating
Created October 18, 2024 05:17
Show Gist options
  • Save StartAutomating/abb3896a9d05661a400bb471eaf52168 to your computer and use it in GitHub Desktop.
Save StartAutomating/abb3896a9d05661a400bb471eaf52168 to your computer and use it in GitHub Desktop.
Gist tell me how bright it is
filter GetLuma {
$colorString = $_
# Convert the background color to a uint32
$rgb = ($colorString -replace "#", "0x" -replace ';') -as [UInt32]
# then make it into a percentage red, green, and blue.
$r, $g, $b = ([float][byte](($rgb -band 0xff0000) -shr 16)/255),
([float][byte](($rgb -band 0x00ff00) -shr 8)/255),
([float][byte]($rgb -band 0x0000ff)/255)
# Calculate the luma of the background color
0.2126 * $R + 0.7152 * $G + 0.0722 * $B
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment