How to export to jpg with filename consisting of the image name and artboard dimension.

New Here ,
May 11, 2021 May 11, 2021

Copy link to clipboard

Copied

Hello all,

What I have is;

- A document with variable sized artboards
- Each artboard contains one image


What I need is;

- Export to jpg (some on 72ppi, some on 144ppi)
- The file name of each jpg containing the image name + the artboard dimensions.


I've been trying to combine different (working) scripts that I have found, which will do a part of the job, without succes. Mainly because I'm quite a noob in scripting.

Is there anyone with a solution for getting the jpg's with the right names?

 

Would be great!

Regards Meart

TOPICS
How to, Import and export, Scripting

Views

334

Likes

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
Adobe Community Professional ,
May 11, 2021 May 11, 2021

Copy link to clipboard

Copied

Hi,

 

The name of the jpeg could probably be collected from the links panel,  app.activeDocument.links is the easy way to get all links, you can then call for each link parent, which can be a story, graphic, movie, or sound.  Once you have the object you can get that page it is on. something like


var aLinks = app.activeDocument.links;
for ( var i = 0; i < aLinks.length; i++){
    var linkName = aLinks[i].name;
    var parentPageItem = aLinks[i].parent;
    var parentPage = parentPageItem.parentPage;
}

 

No when you say 'artboard' do you mean 'Page' or 'Spread'?

 

if you mean spread, then you should be able to call

parentPage.parent

This will return the spread that the link is on, BUT I don't think there is a spread.size or similar call, so you would have to work that out based on other factors. ( let us know if this is the case and we can investigate)

 

If it is Page, then we already have that and you can just call

parentPage.bounds,

which gives you are rectangle of co-ords, which could be transformed into what you need ( I think).

 

I hope this helps, please feel free to ask follow up questions

 

Likes

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
New Here ,
May 12, 2021 May 12, 2021

Copy link to clipboard

Copied

Thanks! Indeed it's about pages.

 

It's about a base document with about 35 pages in different dimensions. This document will be filled with new images every month. Different images with different croppings.

 

Looking at the dimensions; I was able to use a script that takes the copy (e.g. 1600x1600) in a specific paragraph style in the slug area of each page.

 

Next thing I tried to do was adding a live caption before the dimension copy but the script doesn't recognize this as copy. Maybe the solution is to convert the live captions to static? But I have no clue how to implement this in the code below.

 

if (app.documents.length != 0){
var myDoc = app.activeDocument;
MakeJPEGfile();
}
else{alert("Please open a document and try again.");}

function myPS(){
try{return myDoc.selection[0].appliedParagraphStyle;}
catch(e){alert("Place cursor to text with paragraph style for filenames"); exit();}
}

function MakeJPEGfile(){
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.high;
app.jpegExportPreferences.exportResolution = 72;
app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;

app.findGrepPreferences = null;
app.findGrepPreferences.appliedParagraphStyle = myPS();
var f = myDoc.findGrep();

for (var myCounter = 0; myCounter < f.length; myCounter++){
try{
var curPage = f[myCounter].parentTextFrames[0].parentPage;
if (curPage.appliedSection.name != "") {curPage.appliedSection.name = "";}
var objName = f[myCounter].contents.replace(/ /g,"_").toLowerCase();

app.jpegExportPreferences.pageString = curPage.name;
var myFilePath = myDoc.filePath + "/" + objName + ".jpg"; //export to a folder of the current document
var myFile = new File(myFilePath);
myDoc.exportFile(ExportFormat.jpg, myFile, false);
}
catch(e){}//pasteboard?
}
}

 

 

 

Likes

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
Adobe Community Professional ,
May 12, 2021 May 12, 2021

Copy link to clipboard

Copied

Pages have a bounds property, so maybe something like this would work?

 

var doc = app.documents.item(0);
var pgs = doc.pages;
var fp = doc.filePath + "/" + doc.name.replace(/\.[^\.]+$/, '')
var w, h, pn, fn;
app.scriptPreferences.measurementUnit = MeasurementUnits.PIXELS
for (var i = 0; i < pgs.length; i++){
    h = pgs[i].bounds[2] - pgs[i].bounds[0];
    w = pgs[i].bounds[3] - pgs[i].bounds[1];
    pn = pgs[i].name;
    app.jpegExportPreferences.properties = {pageString:pn, jpegQuality:JPEGOptionsQuality.high, exportResolution:72}
    fn = fp +  '-' + pn + '_' + w + 'x' + h + '.jpg'
    doc.exportFile(ExportFormat.jpg, File(fn), false);
}; 

Likes

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
Adobe Community Professional ,
May 12, 2021 May 12, 2021

Copy link to clipboard

Copied

LATEST

Sorry, my example is writing the ID file name not the link name you asked for. Maybe this:

 

 

var doc = app.documents.item(0);
var pgs = doc.pages;
var fp = doc.filePath + "/"
var w, h, pn, fn, ln;
app.scriptPreferences.measurementUnit = MeasurementUnits.PIXELS
for (var i = 0; i < pgs.length; i++){
    h = pgs[i].bounds[2] - pgs[i].bounds[0];
    w = pgs[i].bounds[3] - pgs[i].bounds[1];
    pn = pgs[i].name;
    try {
        ln = pgs[i].allGraphics[0].itemLink.name.replace(/\.[^\.]+$/, '');
    }catch(e) {
        ln = "No Image";
    }  
    app.jpegExportPreferences.properties = {pageString:pn, jpegQuality:JPEGOptionsQuality.high, exportResolution:72}
    fn = fp + "pg" + pn + "-" + ln + '_' + w + 'x' + h + '.jpg'
    doc.exportFile(ExportFormat.jpg, File(fn), false);
};   

 

Likes

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
Adobe Community Professional ,
May 11, 2021 May 11, 2021

Copy link to clipboard

Copied

If all you want exported is the image then you might be better off using Photoshop.

 

Open an image in Photoshop and save it in a format you don’t want to use for your action. You want jpegs? Save as a TIFF.

Create a new action in the Actions panel. Change the resolution to the resolution you want (e.g. 72 ppi) for resampling on. Save as and choose the format you do want. Don’t change the filename. Close the file then stop recording the action.

 

You now have an action that changes the resolution and saves as a JPEG but doesn't change the filename. Now run it as a bath on a folder of images. You can change the destination for the converted files.

Likes

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
New Here ,
May 12, 2021 May 12, 2021

Copy link to clipboard

Copied

Hello Scott,

 

Thanks for your idea. We just stepped away from photoshop since it became to much work with all those different artboards, layers and links.

We tried XD for a while but the issue we bumped into was the fact that images are never linked like we know from PS and ID. Result was that we could not do an instant check if all images were updated. Hopefully in a future upate...

 

Regards Maart

Likes

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