Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Using a script to get the color of a colorized Black & White Bitmap image

Engaged ,
Oct 25, 2013 Oct 25, 2013

I've been running into this wall for quite some time and would greatly appreciate any help that can given for it.

I have an Illustrator script that runs inside of a BridgeTalk session within an InDesign script.  Yeah, it's complicated.  The upshot is that the Illustrator part opens up an EPS file, looks through all objects on a certain layer in that file, and returns an array of the colors used in it.  So, it looks at fill colors, stroke colors, gradient stops, etc.  One of the biggest stumbling blocks (next to PlugIn Items, which I'll ask about in a separate post) is getting the color of raster images.

Most raster images, I realize, are going to be CMYK or RGB images, but our company mostly deals with either Grayscale images or Black & White Bitmaps that are embedded in the EPS file.  Those two allow the ability to colorize them by simply selecting them and then choosing a color, such as a spot PANTONE color from one of their color books.

Now, I need the script to read the color that the raster image has been colorized with.  This works okay for images that have a GrayScale color space, as the script just looks at Colorant[0] of that image.  However, I run into a problem with Black & White Bitmap images.  Here's a piece of code that I try to make work with an EPS file that has a raster image:

var document = app.activeDocument;

for (var i = 0; i < document.layers[0].pageItems.length; i++) {

          // Stepping through each item on the layer.

          var currentItem = document.layers[0].pageItems;

          $.writeln("Current item is " + currentItem.typename);

          $.writeln("Number of channels is " + currentItem.channels);

          $.writeln("Color Space is " + currentItem.imageColorSpace);

          $.writeln("Colorized Grayscale? " + currentItem.colorizedGrayscale);

          $.writeln("Number of Colorants: " + currentItem.colorants.length);

          for (var j = 0; j < currentItem.colorants.length; j++)

          {

                    $.writeln("Colorant number " + j + " is " + currentItem.colorants);

          }

          $.writeln("Its parent is " + currentItem.parent);

          $.writeln("Parent's typename is " + currentItem.parent.typename);

}

This code runs successfully on an Illustrator file that has a Black & White Bitmap image on the top layer, but if you try and run it, you'll see the problem:  Even if you've colorized your Bitmap image with a PANTONE spot color (and the script even returns "true" on the line "Colorized Grayscale?"), Colorant number 0 is "Gray".  It should be the spot color assigned, not "Gray".

Can anyone please help me figure out how to get the script to recognize the actual colorant of a Black & White Bitmap image in Illustrator?

TOPICS
Scripting
2.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Explorer ,
May 25, 2019 May 25, 2019

Did you ever figure this out? I am working on a script to threshold everything in an illustrator file to black or white and the only thing I am stumped on is how to to find out what color has been assigned to a placed bitmap.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 28, 2019 May 28, 2019

Hey, kayr23628964.    

Unfortunately, I never did get an answer, nor did I discover one on my own. To my knowledge, the bug exists to this day. So instead, I came up with a (admittedly kludgey) workaround for our company's art department:

Since our script relies on being able to pick the spot color of a colorized Black & White Bitmap image, we have to trick the script into seeing it. We do so by just creating a rectangle (or oval, or whatever) that is filled with the same spot color as the Black & White Bitmap image, group it together with that image (and any other artwork, in our workflow), then hide it.

Our script is written to gather all colors used, both as fills, strokes, gradients, etc., whether or not they are hidden, and add it to the list of "used colors." Since the path is hidden, however, it won't print or show up on our proof page (something specific to our workflow, of course).

I don't know if doing something similar to this will help in your workflow, but perhaps it might give you an idea or two on how to come up with your own workaround. At least until Adobe gets their $#!+ together and fixes this scripting bug (among many others).

One thing that might be of help in your situation is density. You might be able to convert a Color object to an Ink object, then get that Ink's density through its InkInfo property. I haven't tried it myself in Illustrator, but I did do this exact same thing in InDesign. In that app, it's called neutralDensity and is a direct property of Ink (without having to go through an InkInfo property to get/set it). I believe I had to go through Color and/or Swatch in order to do so. (It's been a long time since I coded that massive portion of our script, so my memory is a bit fuzzy.) In this manner, I was able to list all of the spot colors used in a piece of art in order from darkest to lightest (or vice-versa).

I do hope this helps in some manner. Let us know how things go, too! ☺️

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 28, 2019 May 28, 2019

Thanks for your thoughtful reply. I came up with this hack that seems to work.

If I select the rasterItem the fill palette gets assigned the color of the rasterObject. Then you can make a new pathItem which will use that fillColor by default.

app.selection = rasterItems[0];

var box = pathItems.rectangle(0, 0, 1, 1, false );

box.filled = true;

// box.fillColor is the fill color of the rasterItem

box.remove();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 28, 2019 May 28, 2019
LATEST

I like that solution. I will very likely try that out when I do my big redesign of our scripts in the near future. Thank you, kayr23628964​!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines