Skip to content

Instantly share code, notes, and snippets.

@fedyk
Forked from tqc/rgbatorgb.js
Created March 11, 2019 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fedyk/9718ca1b8d4a23def93f1b6b1395a411 to your computer and use it in GitHub Desktop.
Save fedyk/9718ca1b8d4a23def93f1b6b1395a411 to your computer and use it in GitHub Desktop.
Convert RGBA to RGB
function RGBAtoRGB(r, g, b, a, r2,g2,b2){
var r3 = Math.round(((1 - a) * r2) + (a * r))
var g3 = Math.round(((1 - a) * g2) + (a * g))
var b3 = Math.round(((1 - a) * b2) + (a * b))
return "rgb("+r3+","+g3+","+b3+")";
}
$("#result").html(RGBAtoRGB(225,110,0,0.5,255,255,255));
@fedyk
Copy link
Author

fedyk commented Mar 11, 2019

How to get color opacity from origin color and resulted(based on r canal)

var a = (r3 - r2) / (r - r2);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment