Last active
August 29, 2020 07:05
-
-
Save quantixed/bb4f84f0e79c4a0668e5782ccfde84b7 to your computer and use it in GitHub Desktop.
Export ai files to PNG with our preferred settings for manuscript figures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**************************************************************** | |
* Script to save a directory of ai files to PNG | |
* Options are: white bakcground, 300 dpi and clipped to artboard | |
*****************************************************************/ | |
var folder = Folder.selectDialog(); | |
if (folder) { | |
var files = folder.getFiles("*.ai"); | |
for (var i = 0; i < files.length; i++) { | |
var currentFile = files[i]; | |
app.open(currentFile); | |
var activeDocument = app.activeDocument; | |
var pngFolder = Folder(currentFile.path + "/PNG"); | |
if (!pngFolder.exists) | |
pngFolder.create(); | |
var fileName = activeDocument.name.split('.')[0] + ".png"; | |
var destinationFile = File(pngFolder + "/" + fileName); | |
// set options here for export | |
var opts = new ImageCaptureOptions(); | |
opts.resolution = 300; | |
opts.antiAliasing = true; | |
opts.transparency = false; | |
try { | |
activeDocument.imageCapture(new File(destinationFile), activeDocument.controlBounds, opts); | |
} catch (e) { | |
} | |
activeDocument.close(SaveOptions.DONOTSAVECHANGES); | |
currentFile = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A note on this code. There's two options to export PNG in illustrator
ExportType.PNG24
andimageCapture
. WithExportType.PNG24
I could useExportOptionsPNG24.artBoardClipping = true
but I could not set the resolution. WithimageCapture
it was possible to set the resolution but the clip to artboard setting was hard to find. The second optional argument inimageCapture
allows the user to set bounds andcontrolBounds
is the artboard (AFAICT, the documentation is poor on this point, but otherwise excellent).