How cut/crop an image and duplicate it in basil.js

204 Views Asked by At

I'm trying to do a script in basil.js to duplicate an image and cut/crop the image inside the frame. In the basil.js reference (http://basiljs.ch/reference/) I don't find a function to move the image inside the Indesign frame.

#includepath "~/Documents/;%USERPROFILE%Documents";
#include "basiljs/bundle/basil.js";

function draw() {

    for(var n=0; n<800; n+=100){
        for (var c=0; c<800; c+=100){
        var img = b.image('image-example.jpg', n, c, 100, 100);
        }
    }

}

b.go();

Anyone have an idea how do this with basil.js or java code ? Thanks

Ref: https://i.stack.imgur.com/qwWmK.jpg

1

There are 1 best solutions below

0
On BEST ANSWER

try something like this for placing an image and moving its inner position within a rect:

#includepath "~/Documents/;%USERPROFILE%Documents";
#include "basiljs/bundle/basil.js";

function draw() {
  var frame = b.rect(0,0,300,100);
  var imgFile = new File("/Users/bene/Desktop/image.jpg");
  frame.place(imgFile);
  // optional FitOptions e.g.
  frame.fit( FitOptions.FILL_PROPORTIONALLY );
  frame.fit( FitOptions.CENTER_CONTENT );

  // print current inner position
  b.println( frame.allGraphics[0].geometricBounds );

  // change inner pos
  var x = 100;
  var y = 50;
  var bounds = frame.allGraphics[0].geometricBounds;
  frame.allGraphics[0].geometricBounds = [y, x, bounds[2], bounds[3]];

  // print new inner pos
  b.println( frame.allGraphics[0].geometricBounds );
}

b.go();