silvercover Posted October 19, 2014 Share Posted October 19, 2014 Hi, Assume that I have 50 RGB color values and I want to mix all of them and reach to a final single value which is mixture of all. how can I do that in PHP. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/291932-mixing-rgb-color-values/ Share on other sites More sharing options...
ginerjm Posted October 19, 2014 Share Posted October 19, 2014 (edited) What do you mean by "mix all of them"? You mean you want to come up with a color consisting of blending all those colors? Kind of a meaningless task since the outcome is probably going to be #ffffff anyway. Think about it. What if you took 50 buckets of paint and put them all in a vat. What would it look like? What way would you take 50 six digit numbers and mix them up? Take a sum? Or maybe take each in 2-digit pairs and average them to get some kind of approximation of the same color (r,g,b) ? Edited October 19, 2014 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/291932-mixing-rgb-color-values/#findComment-1494201 Share on other sites More sharing options...
QuickOldCar Posted October 19, 2014 Share Posted October 19, 2014 It isn't like paint, they don't mix. They are 0 to 255. If you added them up or merged would exceed those values. Quote Link to comment https://forums.phpfreaks.com/topic/291932-mixing-rgb-color-values/#findComment-1494202 Share on other sites More sharing options...
Zane Posted October 20, 2014 Share Posted October 20, 2014 It's not going to be as easy as getting the average of the two colors. You're going to have to convert to something like CMYK/HSL/HSV and so on, perform some extremely complex algorithms, and get a result that you would then convert back to RGB. (hex) Your best bet, and easiest alternative without re-inventing the wheel is to find a jQuery plugin that can do it for you, such as this one http://www.xarg.org/project/jquery-color-plugin-xcolor/ Quote Link to comment https://forums.phpfreaks.com/topic/291932-mixing-rgb-color-values/#findComment-1494247 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.