RGBA to Hex Converter Online Tool
About RGBA to Hex Converter Online Tool:
This online RGBA to Hex converter tool helps you to convert one RGBA color (base 10) into a Hex color (base 16), and test the result color within the website.
RGBA Color System:
The RGBA color ("R" stands for "Red", "G" stands for "Green", "B" stands for "Blue") is specified how much red, green and blue light are combined together, and what the overall opacity. The syntax is rgba(16,110,190,0.7)
.
Hex Color System:
the Color System used in HTML is also be written down as Hex number, from #000000
(pure black) to #FFFFFF
(pure white). For example, #123456
means the Red is "12" (in range
"00" to "FF"), the Green is "34", the Blue is "56". The Hex color system also support 3-digits color, for example, color #e1a
is equivalent to #ee11aa
.
How to convert from RGBA to Hex?
Step 1: Get the decimal number of each sub-color (Red, Green and Blue) and the opacity value.
Step 2: Convert each decimal number into hex number.
Step 3: Write the Hex Color result String in correct syntax.
Example: Convert RGBA Color "rgba(16,110,190,0.66)" to Hex Color (result is "#106ebe" with opacity 66%):
Step 1: | RGBA Color "rgba(16,110,190,0.66)": Red(16), Green(110), Blue(190), Opacity(0.66) |
Step 2: | Red: (16)->(0x10), Green: (110)->(0x6e), Blue: (190)->(0xbe), Opacity: (0.66)->(66%) |
Step 3: | RGB Color "rgba(16,110,190,0.66)" -> "#106ebe" with opacity 66% |
More information:
Wikipedia (Web colors): https://en.wikipedia.org/wiki/Web_colors
Wikipedia (RGBA color space): https://en.wikipedia.org/wiki/RGBA_color_space
Convert RGBA to Hex with Python:
import re def rgb_to_hex(rgb_color): rgb_color = re.search('\(.*\)', rgb_color).group(0).replace(' ', '').lstrip('(').rstrip(')') [r, g, b] = [int(x) for x in rgb_color.split(',')] # check if in range 0~255 assert 0 <= r <= 255 assert 0 <= g <= 255 assert 0 <= b <= 255 r = hex(r).lstrip('0x') g = hex(g).lstrip('0x') b = hex(b).lstrip('0x') # re-write '7' to '07' r = (2 - len(r)) * '0' + r g = (2 - len(g)) * '0' + g b = (2 - len(b)) * '0' + b hex_color = '#' + r + g + b return hex_color rgb_input = 'rgb(7,110,190)' hex_output = rgb_to_hex(rgb_input) print('Hex color result is:{0}'.format(hex_output)) ------------------- Hex color result is:#076ebe