Last active
August 29, 2015 14:17
-
-
Save ibanez270dx/f008f811f82b46aecfa5 to your computer and use it in GitHub Desktop.
Convert Hex color to RGBA
This file contains 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
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