Save for web in Illustrator script
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 !
Explore related tutorials & articles
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.
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:
For the alerts, indeed I removed the "Overwrite existing document?" box.
Copy link to clipboard
Copied
Anyone who could help me on this ? I would be really grateful. 🙂
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?
Copy link to clipboard
Copied
"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?

