InDesign CS6 script - Export JPG Images with Original Filename into New Folder

My first real InDesign script.

//What it does:
1. Export framed images from InDesign into individual JPG images.
2. These images will be named the same file name as the original linked file.
3. JPEG Settings: Progressive, Medium quality, 72 dpi, RGB (You can change these, but not sure about changing RGB - CMYK).
4. Images saved into created folder: "JPG webexport".

1. The image size will be the same size as the frame of the image.
2. All framed images will be exported.
3. You gotta change the folder; absolute location (two instances).
4. If you know how to change the output folder into same location as the .indd file, PLEASE do tell. I couldn't figure this out.

//If you want to edit it:
1. You may open the file with Notepad (or other).
2. Change stuff.
3. Save it.
4. Make sure extension is .jsx.

DOWNLOAD LINKS (Google Drive):

// Credit where it's due.
These were my main sources. Thank you very much to the helpful guys and gals of StackExchange/StackOverflow :')

Now, I'm pretty sure the script can still be cleaned up, but being that this already took up almost two of my work days, I ain't gonna fix what's not broken :')


//Script in text below (Select to COPY from BELOW here):

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

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

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

    app.jpegExportPreferences.exportResolution = 72;
    app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MEDIUM;

    //make new folder
    var f = new Folder("c:/users/Shadouness/desktop/JPG webexport/"); 

    //give it a unique name
    var myFile = new File('c:/users/Shadouness/desktop/JPG webexport/' + fileName);

    rect.exportFile(ExportFormat.JPG, myFile);

// (Select to COPY until ABOVE here)

No comments: