Skip to content

Instantly share code, notes, and snippets.

@stevendaniels
Last active July 14, 2017 04:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevendaniels/41c722b56ffe59b74b5e to your computer and use it in GitHub Desktop.
Save stevendaniels/41c722b56ffe59b74b5e to your computer and use it in GitHub Desktop.
ARGB to RGBA CSS Value
# 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