0

We are working on Abode Illustrator to create SVG files, we are trying to create javaScripts to list all the color codes coded in the SVG file.

And also trying to get the count of each color coded in each objects in the SVG.

Required Result

Result using JavaScript

We tried using the solution provided in the below link provided by @Emeeus. Link: Illustrator script to find all colors in document

We opened the SVG file in a empty web page and ran the below code in the Console:

var doc = document.getElementsByTagName("*");
               var colors = [];

               for (let j = 0; j < doc.length; j++) {

               var styles = window.getComputedStyle(doc[j], null)

               for (let i = 0; i < styles.length; i++) {

if (typeof styles[styles[i]] !== "undefined" && styles[styles[i]].match(/rgb\([0-9, ]*\)/g)) {

let color = styles[styles[i]].replace(/(.*)(rgb\([0-9, ]*\))(.*)/g,"$2")
  if (!colors.includes(color))
    colors.push(color);

}

 }

  }
 console.log(colors)

It does give you the list of color codes used in the file. But there are more 2 requirements we need:

  1. The color code is in RBG form, we require the same in HEX code.
  2. The count of each color code is not extracted in the output.

Getting out using the above code: Result using JavaScript

Required Result

Sam Shetty
  • 11
  • 1
  • Please edit your post and format the code parts properly. It's hard to read like this. – ush189 Apr 15 '19 at 10:01
  • Apologies, this is the first time i'm using StackOverFlow to help resolve our query. Have tried editing again, let me know if the query is understandable. Thank you. – Sam Shetty Apr 15 '19 at 14:47

0 Answers0