Skip to main content
Inspiring
January 25, 2019
Question

Save for web in Illustrator script

  • January 25, 2019
  • 1 reply
  • 2180 views

I made an Illustrator script to batch resize and center JPG pictures.

I would like to export the files by sticking it to artboard while keeping a 96 DPI.

The classical export as JPG recorded script works, but the size of the picture is based on DPI while it should be the same dimension as the artboard.

I recorded another script with Export for web action, but I need to confirm the export for each picture while I have DONTDISPLAYALERTS.

Now I found a direct way to add this action to the script, but apparently it only works with Photoshop:

function main(){ 

if(!documents.length) return; 

var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');  

var saveFile = File(Folder.desktop + "/" + Name + ".jpg"); 

if(saveFile.exists){ 

   if(!confirm("Overwrite existing document?")) return; 

    saveFile.remove(); 

    } 

SaveForWeb(saveFile,100); //change to 60 for 60% 

main(); 

function SaveForWeb(saveFile,jpegQuality) { 

var sfwOptions = new ExportOptionsSaveForWeb();  

   sfwOptions.format = SaveDocumentType.JPEG;  

   sfwOptions.includeProfile = false;  

   sfwOptions.interlaced = 0;  

   sfwOptions.optimized = true;  

   sfwOptions.quality = jpegQuality; //0-100  

activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions); 

}

Would you know which Illustrator function can replace ExportOptionsSaveForWeb() ?

Thank you !

This topic has been closed for replies.

1 reply

Silly-V
Legend
January 25, 2019

It's Document.exportFile(file, exportType, saveOptions)

And you have to use the ExportOptionsJPEG as the save-options argument as well as ExportType.JPEG as the export type argument.

I'm not sure what you wish to accomplish by confirming every document when it exports while you're not displaying alerts. Perhaps you may be interested in using a dynamic action to play an export action with the settings baked-in that you wish, but with the show-dialog option turned on. This way you could accomplish some settings pre-population and still show the export dialog each time.

However this makes the user have to press some button for each file.

Inspiring
January 25, 2019

Hi Silly-V, when I used Document.exportFile, the size of the output picture was bigger than the artboard size (it was actually linked to DPI option).

This problem is solved using a recorded action, but only partly because the following screen is displayed when exporting each picture, and I want the script to work wihout any user interaction:

For the alerts, indeed I removed the "Overwrite existing document?" box.

Inspiring
January 29, 2019

Anyone who could help me on this ? I would be really grateful. :)