0

I am trying to automate the process of image tracing images in Illustrator. I have a good system with black and white images where I can create an action to trace, save as SVG and remove white after with the "Select Same" and choosing "fill color". But I can't get it to work at all when doing with color images.

One of the issues is that I can't find a way to automate removnig white from images when doing a trace. This wouldn't be a problem if all of the white had the exact same color code (i.e. 255,255,255) but often it has some sections that have different variations of white and I can't remove them all at once with an action.

I have tried a few different things:

  1. I created a custom preset that ignores white. It works fine when I run it in Illustrator on a single image, but when I use Adobe Bridge the white is still there.
  2. I have tried copying the "Image Tracing Script" and modifying it to choose the right preset by changing the "3" in t.tracing.tracingOptions.loadFromPreset(tracingPresets[3]); to other numbers. But I can never get it to the right preset and the index doesn't seem to match the order in my preset list.
  3. I have tried adding a background with a different color in Photoshop so there wouldn't be any white at all and then using "Select Same" to choose that as the fill color to remove. But I run into the same issue again where the color codes vary from image to image so I can't do it in batch.

Does anyone have any thoughts on something I am doing wrong on any of these steps or something that I haven't tried? I didn't try changing the Vectorizing Presets file yet, so might give that a try. But would be open to fixing any possible mistakes in my other steps.

1
  • Maybe get the script to select any object with RGB values all greater than 250 (or whatever threshold works for you) Commented Feb 13 at 19:09

1 Answer 1

2

Here is the script:

var threshold = 250;
var items = app.activeDocument.pathItems;

for (var i = items.length-1; i > 0; i--) {
    var color = items[i].fillColor;
    if (color.red > threshold && color.green > threshold && color.blue > threshold) {
        items[i].remove();
    }
}

It removes every path items if all of its fill color's components (red, green and blue) exceeds the threshold. You can tweak the threshold variable as you need.

1
  • 1
    thanks yuri. I was just coming to update this and say that I came up with a script that did something very similar. Yours is more concise and elegant, but accomplishes the same thing
    – kman99
    Commented Feb 14 at 19:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.