Search code examples
adobe-indesign

Adobe Indesign Script to Crop Selected Images


Looking for some help in figuring out how to write a script to crop images in Indesign. The images are of two sides of an object, so usually I drag the image in from the folder, copy it and crop both images vertically so I end up with separate objects for the left-hand(front) and right-hand(back) sides of whatever I'm playing with.

I had a search of forums but most of the scripts I found were aimed at a simple resize rather than basically cutting an image in half vertically while leaving the size unchanged - can anyone help me get started on this?

Thanks!


Solution

  • Try this:

    var sel = app.selection[0];
    
    app.copy();
    
    var gb = sel.geometricBounds;
    gb[3] -= (gb[3]-gb[1])/2;
    sel.geometricBounds = gb;
    
    app.pasteInPlace();
    
    var sel = app.selection[0];
    
    var gb = sel.geometricBounds;
    gb[1] += (gb[3]-gb[1])/2;
    sel.geometricBounds = gb;
    

    It 'crops' selected image (left-hand half), copy/pastes (inplace) the image again and crops its again (right-hand half)

    enter image description here