2

I am new to Indesign. I have a file that contains images with Photoshop clipping paths. I want to export all the clipped images in a folder. I have tried doing the "Copy Links To" and it successfully exported the original images. However, I do not want the original images but the clipped images instead. Is there a way for me to export all the clipped images as JPEG or TIFF and not the original linked image? In short, I want to export the images without their background. I hope I'm making sense. I have about 800-1000 images so a batch processing method would be highly appreciated.

I actually found a way to export the images the way I want them to be. I just need to click the image container (not the image), go to File>Export and then export it as JPEG. In the pop up window, I choose export selection, maximum quality, and 2400 resolution. It exports the images the way I want them to be. But I have to do this one by one. I just have two concerns:

  1. Is there a way for me to do this by batch? Like select all the image containers and export them one by one automatically?

  2. Is there a way to automatically name the saved files according to the original image name?

Thank you for your help!

Update: I found this script from one of the posts here and modified it a bit to suit my needs. It appears to work in most of my INDD documents, but it fails in others. I wonder why. I sometimes get the error message that

Error string: null is not an object

Source: fileName = File ( rect.graphics[0].itemLink.filePath ).name;

I also noticed that it skips some objects and won't download all of the images. I guess it skips those that are not in rectangles.

test();
function test()
{
var myDoc = app.activeDocument,
apis = myDoc.allPageItems, rect, fileName;

while ( rect = apis.pop() )
{
if ( !(rect instanceof Rectangle) || !rect.graphics[0].isValid ){ continue;}


fileName = File ( rect.graphics[0].itemLink.filePath ).name;
fileName = fileName.replace( /\.[a-z]{2,4}$/i, '.jpg' );


app.jpegExportPreferences.exportResolution = 2400;
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;


//give it a unique name
var myFile = new File ("C:/Users/RANFacistol-Mata/Desktop/Image Trial/"+ fileName);


rect.exportFile(ExportFormat.JPG, myFile);
}
}

Is there a way for me to modify this script such that instead of iterating through all the rectangles, I would iterate through all of the objects instead, much like clicking this next button

And then check if that object contains an image (jpg, tiff, psd, ai, eps). If it does, then I will export it as scripted above.

Thank you for your help!

1

Thank you for your inputs. I have combined all the answers I got from all the different forums I asked help from and finally came up with a script that iterates only through the linked images and disregards whether the container is a rectangle, polygon, or whatever. I also added a counter so that the images won't get overwritten in case the names are the same.

var myDoc = app.activeDocument,
apis = myDoc.links.everyItem().getElements(), items, fileName;
var i = 0;

while ( items = apis.pop() )
{
    items = items.parent.parent;  
    if ( !(items.hasOwnProperty ("graphics") )){ continue; }
    i++;
    try{
        fileName = File ( items.graphics[0].itemLink.filePath ).name;
        fileName =  i + "_" + fileName.replace( /\.[a-z]{2,4}$/i, '.jpg' );
    }catch(e){};

    app.jpegExportPreferences.exportResolution = 2400;
    app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;

    //give it a unique name
    var myFile = new File ("Mypath"+ fileName);

    items.exportFile(ExportFormat.JPG, myFile);
}
0

Yes, to check all page items for images, not just rectangles, you just need to remove the !(rect instanceof Rectangle) part. And while you're at it, also rename the variable from rect to something like pageItem, so it describes what it actually holds. So your script should look like this then:

var myDoc = app.activeDocument,
apis = myDoc.allPageItems, pageItem, fileName;

while ( pageItem = apis.pop() ) {
  if ( !pageItem.graphics[0].isValid ){ continue;}

  fileName = File ( pageItem.graphics[0].itemLink.filePath ).name;
  fileName = fileName.replace( /\.[a-z]{2,4}$/i, '.jpg' );

  app.jpegExportPreferences.exportResolution = 2400;
  app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;

  //give it a unique name
  var myFile = new File ("C:/Users/RANFacistol-Mata/Desktop/Image Trial/"+ fileName);


  pageItem.exportFile(ExportFormat.JPG, myFile);
}
0

Replace

if ( !(rect instanceof Rectangle) || !rect.graphics[0].isValid ){ continue;}

by

if ( !(rect instanceof Rectangle) && !(rect instanceof Oval) && !(rect instanceof Polygon)|| !rect.graphics[0].isValid ){ continue;}

Please note that if you have same graphic imported several times, last occurrence of this graphic will replace all others.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.