0
$pattern = "/#(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{3})\b/";
if(preg_match_all($pattern, $file, $matches, PREG_PATTERN_ORDER));
$data["colors"] = $matches[0];

So basically what i need to do is manipulate a SVG image so that we can count the number of colors and change the colors of that image using php. From the above code i can find what colors are being used but the problem is that i have to match the colors in another array of colors where if the hex code isn't matched then i have to select the closest match to that color. I have to be able to then save that information to the SVG file.

This is my Color Array:

$pantone = [
    [
        "Pantone" => "Yellow",
        "Hex" => "FEDD00",
        "R" => "254",
        "G" => "221",
        "B" => "0"
    ],
    [
        "Pantone" => "Yellow 012",
        "Hex" => "FFD700",
        "R" => "255",
        "G" => "215",
        "B" => "0"
    ],
    [
        "Pantone" => "Orange 021",
        "Hex" => "FE5000",
        "R" => "254",
        "G" => "80",
        "B" => "0"
    ],
    [
        "Pantone" => "Warm Red",
        "Hex" => "F9423A",
        "R" => "249",
        "G" => "66",
        "B" => "58"
    ],
    [
        "Pantone" => "Red 032",
        "Hex" => "EF3340",
        "R" => "239",
        "G" => "51",
        "B" => "64"
    ],
    [
        "Pantone" => "Rubine Red",
        "Hex" => "CE0058",
        "R" => "206",
        "G" => "0",
        "B" => "88"
    ],
    [
        "Pantone" => "Rhodamine Red",
        "Hex" => "E10098",
        "R" => "225",
        "G" => "0",
        "B" => "152"
    ],
];

This is link to my SVG with Regex

Please do inform me if i am incomplete in my question.

  • You want a solution in javascript or php? – sabithpocker Nov 21 '16 at 07:09
  • PHP would be better since i am working on it. – Subin Shakya Nov 21 '16 at 07:09
  • 1
    There is a function here that you can directly use: http://stackoverflow.com/questions/4485229/rgb-to-closest-predefined-color – phobia82 Nov 21 '16 at 07:40
  • First of all, this is not duplicate of the question marked by @Toto , i wanted to change the Hex value, not the RGB And Secondly, I did it myself.. Hooray !! :D All i had to do was just randomize the last digit of the Hex code to find the closest color if exact color was not found!! – Subin Shakya Nov 22 '16 at 07:21

0 Answers0