Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

PHP color related problem


Mouzi's Avatar
Member
0 0

Ok this time I've got a problem with PHP :D I've made a code that takes the images average color. That was the easy part but what I had in mind was a code that would check if the images average color is between certain RGB values. Like if the image is mostly blue or mostly yellow. The problem is that I can't just check for R, G and B that they are between the given R, G and B because it would include other colors too and not only the shades of that certain colour I want the image to be.

So does anyone know any code/way to check if color is between 2 given colors? Or would this go too complicated?

EDIT: I may have thought this wrong too. Probably stupid & impossible idea.


ghost's Avatar
0 0

can you post the code uv got so far?

that might make it easier to see your problem


Mouzi's Avatar
Member
0 0

I only got the average color code (and upload code) but it's already working fine. I only tried to check if the average colors each value (R, G and B) were in between of given R, G and B… But it allows so many other colors so it won't work that way. If you want to see that code it's here:

$keski=explode("-",$keski);
if($keski[0]>103 && $keski[0]<256 && $keski[1]>30 && $keski[1]<223 && $keski[2]>15 && $keski[2]<112) {
$keskicheck = true;
}

$keski is the average color taken from the image and it's R-G-B so that's why I explode "-".


richohealey's Avatar
Python Ninja
0 0

well if that's the average color, and you want to see which color the image tends toward, just find out which value is largest….

so just use the sort() command [i dunno what it is in php, and i can't be arsed grabbing the php5 book behind me and flipping ot the index]

so thar you have it.


Mouzi's Avatar
Member
0 0

Hmm that's actually good idea :) If I use that AND check that all the R, G and B are between the RGB values I use then it might work.

EDIT: I did it like this now:

if($keski[0]>103 && $keski[0]<256 && $keski[1]>30 && $keski[1]<223 && $keski[2]>15 && $keski[2]<112) {
$keskicheck = true;
}
if($keski[0]>$keski[1] && $keski[0]>$keski[2] && $keski[1]>$keski[2]) {
$keskicheck2= true;
}```
Gotta go try if it works -->

Mouzi's Avatar
Member
0 0

Now it's working pretty well. I'm using it to check if the image is sepia like. Though you can still do something like write "LOL" with red in the center and it still passes it :/

But I've got solution for that too :D I check every pixel for sepia color and not the average. (It's almost same as my average script). I didn't think this would actually end up working!

Thanks richohealey!