• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

saving images in a specific folder

Explorer ,
Dec 15, 2021 Dec 15, 2021

Copy link to clipboard

Copied

Hi à la ligne

I use a script to convert all images to jpg format. This part of the script is OK.

 

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

while ( rect = apis.pop() )
{
alert(rect.graphics[0].itemLink.filePath)
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 = 300;
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MEDIUM;

//make new folder
var f = new Folder("C:/Users/laure/Creative Cloud Files/SousLeSoleil_Livre/Links/Images/");
f.create();

//give it a unique name
var myFile = new File('C:/Users/laure/Creative Cloud Files/SousLeSoleil_Livre/Links/Images/' + fileName);

rect.exportFile(ExportFormat.JPG, myFile);

 

I have to specify the file path manualy (bold). 

I would like to save the jpg images in the a new folder (ex.: /images/) in the /Links/ folder anywhere the Package is save.

Is it possible to change this script to do this ?

Thanks for help.

Best

LT

TOPICS
Scripting

Views

173

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Advisor , Dec 15, 2021 Dec 15, 2021

Hello @laurent tourniel7664515,

 

Give this a try...

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

while ( rect = apis.pop() )
{
// alert(rect.graphics[0].itemLink.filePath)
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 = 300;
app.jpegExportPreferences.jpegQuality = JPEGOptions
...

Votes

Translate

Translate
Community Expert , Dec 15, 2021 Dec 15, 2021

Hi LT, The path to a packaged InDesign file’s Links folder would be:

 

var linkFolder = app.activeDocument.filePath + "/Links"

//add an Images folder
var f = new Folder(linkFolder + "/Images/");
f.create();

 

Votes

Translate

Translate
Advisor ,
Dec 15, 2021 Dec 15, 2021

Copy link to clipboard

Copied

Hello @laurent tourniel7664515,

 

Give this a try...

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

while ( rect = apis.pop() )
{
// alert(rect.graphics[0].itemLink.filePath)
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 = 300;
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MEDIUM;

//make new folder
var f = new Folder(myDoc.filePath + "/Links/Images/");
f.create();

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

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

Regards,

Mike

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 15, 2021 Dec 15, 2021

Copy link to clipboard

Copied

Thanks a lot, Mike.

It is perfect.

Best

Laurent

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 15, 2021 Dec 15, 2021

Copy link to clipboard

Copied

LATEST

Hi LT, The path to a packaged InDesign file’s Links folder would be:

 

var linkFolder = app.activeDocument.filePath + "/Links"

//add an Images folder
var f = new Folder(linkFolder + "/Images/");
f.create();

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines