Last active
July 14, 2017 04:36
-
-
Save stevendaniels/41c722b56ffe59b74b5e to your computer and use it in GitHub Desktop.
ARGB to RGBA CSS Value
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
# https://en.wikipedia.org/wiki/RGBA_color_space#ARGB | |
def argb_to_rgba(argb) | |
argb.gsub(/(?<a>..)(?<r>..)(?<g>..)(?<b>..)/) do | |
matches = Regexp.last_match | |
"rgba(#{matches[:r].to_i(16)},#{matches[:g].to_i(16)},#{matches[:b].to_i(16)},#{matches[:a].to_i(16) / 255.0})" | |
end | |
end | |
# argb_to_rgba('FFFF0000') | |
# # => rgba(255, 0, 0, 1.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment