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

Save for web in Illustrator script

Explorer ,
Jan 25, 2019 Jan 25, 2019

Copy link to clipboard

Copied

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 !

TOPICS
Scripting

Views

1.9K
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
Valorous Hero ,
Jan 25, 2019 Jan 25, 2019

Copy link to clipboard

Copied

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.

Votes

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 ,
Jan 25, 2019 Jan 25, 2019

Copy link to clipboard

Copied

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:

2019-01-25_12-38-57.jpg

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

Votes

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 ,
Jan 29, 2019 Jan 29, 2019

Copy link to clipboard

Copied

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

Votes

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
Advisor ,
Jan 29, 2020 Jan 29, 2020

Copy link to clipboard

Copied

Im still shocked why illustrator doesnt have the save or export function Photoshop does have. I mean the save4web functions are super handy. Currently i dont see any of this in the Javascript documents. WOnder why this is not added?

Votes

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 ,
Jan 29, 2020 Jan 29, 2020

Copy link to clipboard

Copied

LATEST

"m still shocked why illustrator doesnt have the save or export function Photoshop does have."

What kind of export do you need? Have tried Asset export? The layer exprt script by Tom Byrne?

Votes

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