Skip to content

Instantly share code, notes, and snippets.

@ibanez270dx
Last active August 29, 2015 14:17
Show Gist options
  • Save ibanez270dx/f008f811f82b46aecfa5 to your computer and use it in GitHub Desktop.
Save ibanez270dx/f008f811f82b46aecfa5 to your computer and use it in GitHub Desktop.
Convert Hex color to RGBA
def hex_to_rgba(input, alpha=1)
components = (input.match /#?([0-9A-F]{2})/ )[1..3]
components.map!{ |x| x + x } if input.size == 4
"rgba(#{components.collect(&:hex).join(',')},#{alpha})"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment