0

I am currently trying to figure out how to change the color of a bitmapped image within indesign using basil.js. Ideally I would like to place the image and use some sort fo post styling to change the color.

var myImage = image('image_0009_10.psd', 0, 0, width, height);
property(myImage, "fillColor", "RISOBlue");

Right now I am using fillColor but that only changes the color of the frame that the bitmap live within. Anyone got any ideas as to how to edit the contents of a graphic frame? Specifically a bitmap?

  • Hey fabianmoronzirfas & mdomino! Glad to be here. This was exactly what I was looking for. I ended up going mdomino's route but both answers are greatly appreciated! – itsphuckinjosh Mar 30 '20 at 14:41

3 Answers3

1

Welcome to STO

You are currently setting the fillColor for the Rectangle that contains the image. You will have to select the image explicitly since it is a child object of that Rectangle. See:

The code below is tested with InDesign 14.0.1 and the current Basil.js Develop version 2.0.0-beta


// @include "./basil.js"
function setup() {
  var doc = app.activeDocument;
  var imageFile = file(new File($.fileName).parent + "/img.bmp");
  var img = image(imageFile, 0, 0, 100, 100);
  img.images[0].fillColor = doc.swatches[4];
}
fabianmoronzirfas
  • 4,091
  • 4
  • 24
  • 41
1

fabianmoronzirfas is correct that you have to target the graphic of the image frame, I just want to suggest a slightly different syntax, which is a bit more basil-like to achieve the same thing:

// @include ~/Documents/basiljs/basil.js

function draw() {

  var myImage = image('~/Desktop/someImage.psd', 0, 0);
  var myGraphics = graphics(myImage);
  property(myGraphics[0], 'fillColor', color(0, 0, 255));

}

Note the use of the graphics() function to get the actual graphics within an image rectangle.

mdomino
  • 1,195
  • 1
  • 8
  • 22
1

graphics() is perfect for this (as @mdomino mentioned) – but can also just grab that property of the image:

var myImage = image('image_0009_10.psd', 0, 0, width, height);
property(myImage.graphics[0], "fillColor", "RISOBlue");

Running inspect(myImage) will give a long laundry list of available properties.