Skip to main content
Participant
September 6, 2020
Answered

AI scripting export to jpeg, Antialiasing Type Optimized

  • September 6, 2020
  • 1 reply
  • 2272 views

Hi,

 

I have a javacript to export hundreds, or even thousands of SVG-files to JPEG.

 

However, I cant find the JPEG setting to get antialiasing Art Optimised or Type Optimized.

 

optionsJPEG.antiAliasing is according to spec only a boolean.

 

Please someone guide me to a workaround.

 

regards Ola

 

 

This topic has been closed for replies.
Correct answer Charu Rajput

Hi,

Try following snippet by Carlos

// export selection by Resolution
// carlos canto - 06/27/2020
// https://community.adobe.com/t5/illustrator/export-jpg-as-300-ppi/td-p/11244200?cid=101&cgid=18269&page=1

function main() {
    var idoc = app.activeDocument;
    var asset = idoc.assets.addFromSelection();
    asset.assetName = 'myExportedAsset';
    
    var destFolder = Folder('~/desktop');
    var resolution = 300;
    exportItem (asset, destFolder, resolution);
    
    var destPath = destFolder + '/mySaveAsFile.jpg';
    exportFileToJPEG (destPath, resolution);
}

function exportItem(item, destFolder, resolution) {
    // turn create folders off, same as unchecking the setting on the UI Export Assets window
    app.preferences.setIntegerPreference ('plugin/SmartExportUI/CreateFoldersPreference', 0); // don't create subfolders
    
    var whatToExport = new ExportForScreensItemToExport();
    whatToExport.assets = [item.assetID];
    whatToExport.artboards = ''; // don't export artboard
    whatToExport.document = true; // don't export document

    var jpgOptions = new ExportForScreensOptionsJPEG;
    jpgOptions.antiAliasing = AntiAliasingMethod.ARTOPTIMIZED; // art optimized results in jagged edges, is it a bug?
    jpgOptions.compressionMethod = JPEGCompressionMethodType.BASELINEOPTIMIZED; // BASELINESTANDARD
    jpgOptions.scaleType = ExportForScreensScaleType.SCALEBYRESOLUTION;
    jpgOptions.scaleTypeValue = resolution;
    
    activeDocument.exportForScreens (destFolder, ExportForScreensType.SE_JPEG100, jpgOptions, whatToExport);
}

main();

function exportFileToJPEG (dest, resolution) {
    
    var exportOptions = new ExportOptionsJPEG();
    var type = ExportType.JPEG;
    var fileSpec = new File(dest);
    exportOptions.antiAliasing = true;
    exportOptions.artBoardClipping = false;
    exportOptions.horizontalScale = resolution*100/72; // scaling increases image physical size, 
    exportOptions.verticalScale = resolution*100/72;
    exportOptions.qualitySetting = 100;
    app.activeDocument.exportFile( fileSpec, type, exportOptions );
}

 

For more reference please read following thread

https://community.adobe.com/t5/illustrator/export-jpg-as-300-ppi/m-p/11244323?page=1#M183146

1 reply

Charu Rajput
Community Expert
Charu RajputCommunity ExpertCorrect answer
Community Expert
September 6, 2020

Hi,

Try following snippet by Carlos

// export selection by Resolution
// carlos canto - 06/27/2020
// https://community.adobe.com/t5/illustrator/export-jpg-as-300-ppi/td-p/11244200?cid=101&cgid=18269&page=1

function main() {
    var idoc = app.activeDocument;
    var asset = idoc.assets.addFromSelection();
    asset.assetName = 'myExportedAsset';
    
    var destFolder = Folder('~/desktop');
    var resolution = 300;
    exportItem (asset, destFolder, resolution);
    
    var destPath = destFolder + '/mySaveAsFile.jpg';
    exportFileToJPEG (destPath, resolution);
}

function exportItem(item, destFolder, resolution) {
    // turn create folders off, same as unchecking the setting on the UI Export Assets window
    app.preferences.setIntegerPreference ('plugin/SmartExportUI/CreateFoldersPreference', 0); // don't create subfolders
    
    var whatToExport = new ExportForScreensItemToExport();
    whatToExport.assets = [item.assetID];
    whatToExport.artboards = ''; // don't export artboard
    whatToExport.document = true; // don't export document

    var jpgOptions = new ExportForScreensOptionsJPEG;
    jpgOptions.antiAliasing = AntiAliasingMethod.ARTOPTIMIZED; // art optimized results in jagged edges, is it a bug?
    jpgOptions.compressionMethod = JPEGCompressionMethodType.BASELINEOPTIMIZED; // BASELINESTANDARD
    jpgOptions.scaleType = ExportForScreensScaleType.SCALEBYRESOLUTION;
    jpgOptions.scaleTypeValue = resolution;
    
    activeDocument.exportForScreens (destFolder, ExportForScreensType.SE_JPEG100, jpgOptions, whatToExport);
}

main();

function exportFileToJPEG (dest, resolution) {
    
    var exportOptions = new ExportOptionsJPEG();
    var type = ExportType.JPEG;
    var fileSpec = new File(dest);
    exportOptions.antiAliasing = true;
    exportOptions.artBoardClipping = false;
    exportOptions.horizontalScale = resolution*100/72; // scaling increases image physical size, 
    exportOptions.verticalScale = resolution*100/72;
    exportOptions.qualitySetting = 100;
    app.activeDocument.exportFile( fileSpec, type, exportOptions );
}

 

For more reference please read following thread

https://community.adobe.com/t5/illustrator/export-jpg-as-300-ppi/m-p/11244323?page=1#M183146

Best regards
schroef
Inspiring
May 25, 2021

how can get real 100o pixels with, i cant see to figure this part out. I tried using the above script or part of it to scale it to 1000dpi, still my pixel document dimensions are low. i tried adding the function which calculates the scale ratio, but then i bump into a scale limit.

 

Im going nuts here, the documents up to 2021 are not updated with info about ExportForScreen properly. The export for screen has the option of width and height as a value, but in the scripting it is referenced as horizontal scale and vertical scale. 

 

Does anyone know how to add the save options for these? 

CarlosCanto
Community Expert
Community Expert
May 25, 2021