Copy link to clipboard
Copied
I am looking to export multiple cropped images on a spread with original linked names and specific dimensions. Do I need a a script for this? Has anyone done this?
I'll attach a preview so you can see the spread with the containers.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi @kevinfabrizi,
I've had a crack at writing a script to solve your challenge. Let me know if this works for you. I've only tested on basic documents, so it might need some tweaking to handle less basic cases.
- Mark
/*
Export All Graphics As JPG
by m1b
here: https://community.adobe.com/t5/indesign-discussions/export-multiple-cropped-images-on-a-spread-with-original-linked-names-and-specific-dimensions/m-p/12490323
Will attempt to export every graphic in a document to a folder, as JPG image at set resolution.
Filename has pixel dimensions appended.
*/
function main() {
var exportResolution = 300; // ppi
exportAllLinkedImagesAsJPG(exportResolution);
function exportAllLinkedImagesAsJPG(resolution) {
resolution = resolution || 300;
var graphics = app.activeDocument.allGraphics;
for (var i = 0; i < graphics.length; i++) {
var graphic = graphics[i],
frame = graphic.parent,
w = Math.round((frame.visibleBounds[3] - frame.visibleBounds[1]) * (resolution / 72)),
h = Math.round((frame.visibleBounds[2] - frame.visibleBounds[0]) * (resolution / 72)),
filename = getFileNameForItem(frame) + '_' + w + 'x' + h;
exportItemAsJPG({
item: frame,
filename: filename,
resolution: resolution,
exportPath: '~/Desktop/exported-jpg-' + resolution + 'ppi/'
});
}
}
function exportItemAsJPG(p) {
if (p.item == undefined) return;
p.filename = p.filename || p.item.constructor.name + ' ' + p.item.index;
p.resolution = p.resolution || 300;
p.exportPath = p.exportPath || '~/Desktop/exported-jpg-' + p.resolution + 'ppi/';
// create the folder if necessary
if (!Folder(p.exportPath).exists) Folder(p.exportPath).create();
// set jpeg preferences
app.jpegExportPreferences.exportResolution = p.resolution; // ppi
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.high; // low medium high maximum
// export
var path = p.exportPath + p.filename + '.jpg';
p.item.exportFile(
ExportFormat.jpg,
File(path),
false
);
}
function getFileNameForItem(item, keepExtension) {
var name = item.constructor.name + ' ' + item.id;
if (item.graphics != undefined) {
if (item.graphics[0].itemLink != undefined) {
name = item.graphics[0].itemLink.name.replace(/\.[^.]+$/, '');
}
}
return name;
}
} // end main
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Export graphics');
Copy link to clipboard
Copied
Very helpful @m1b!
The exportItemAsJPG() function has certainly saved me a lot of time when creating a similar export script.
Thank you very much!
Martin
Copy link to clipboard
Copied
Good to hear, Martin! - Mark
Copy link to clipboard
Copied
Design and position can be done with Object and Paragraph Styles.
Copy link to clipboard
Copied
Nice! I've never used object captions. Great info!
Also I assumed OP wanted the linked image name and dimensions in the *filename*, but you may be right and it should be saved in the jpeg as a visible caption. I'll wait for @kevinfabrizi to clarify.
- Mark