0

So I have used this simple PHP script to get one main colour out of an image. https://stackoverflow.com/a/36321726/7278089

enter image description here The highlighted number is the hex but without a # in front.

 

I want our platform to be able to filter on colors but when a user is creating a post it will search for the one main colour in his image and then save it into the DB. But here is the thing that I'm searching for I don't want to save away for example #0d66ac which is blue. I just want it to insert into the table as color=blue;

Zanic L3
  • 1,028
  • 1
  • 16
  • 28

2 Answers2

1

Use this script to match a color (HEX) with the color "name", you could simply pass the result to PHP.

Subsequently, when a match has been found, pass it off to your table.

http://chir.ag/projects/ntc/ntc.js

Julian Koster
  • 262
  • 1
  • 10
-1

If you want to convert hex to rgb you can use sscanf:

<?php
     $hex = "#ff9900";
     list($r, $g, $b) = sscanf($hex, "#%02x%02x%02x");
     echo "$hex -> $r $g $b";
?>
Kostas St
  • 3
  • 1
  • 8