Manipulating image within Indesign frame

279 Views Asked by At

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?

3

There are 3 best solutions below

0
On BEST ANSWER

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.

0
On

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];
}
0
On

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.