Created
September 5, 2017 19:44
-
-
Save bgribble/e6b35e0af88408fcd93d1726262a5d8b to your computer and use it in GitHub Desktop.
Convert an RGBA color over a background RGB color to RGB
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
import sys | |
if __name__ == '__main__': | |
r = int(sys.argv[1]) | |
g = int(sys.argv[2]) | |
b = int(sys.argv[3]) | |
a = float(sys.argv[4]) | |
if len(sys.argv) > 5: | |
bg_rgb = sys.argv[5] | |
else: | |
bg_rgb = 'ffffff' | |
bg_r = int(bg_rgb[0:2], 16) | |
bg_g = int(bg_rgb[2:4], 16) | |
bg_b = int(bg_rgb[4:6], 16) | |
red = int(r*a + bg_r*(1-a)) | |
green = int(g*a + bg_g*(1-a)) | |
blue = int(b*a + bg_b*(1-a)) | |
print ("rgba(%s, %s, %s, %s) on #%s --> rgb(%s, %s, %s) or #%x%x%x " % ( | |
r, g, b, a, bg_rgb, red, green, blue, red, green, blue)) |
Author
bgribble
commented
Sep 5, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment