Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How do I create a batch script that would export a set of AI files in CS4 to a png of a certain size?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You should have a scripts folder somewhere like this: C:\Program Files\Adobe\Adobe Illustrator CS2\Presets\Scripts. Copy the ExportDocsAsFlash.js to ExportDocsAsPNG24.js and modify using the AI Javascript Reference as a guide.

I tried this w/ CS2 (code below), but there seems to be a bug in the engine. For PNG's (and GIF's it seems) it doesn't access subsequent document objects so it saves the same document each time. Hopefully CS4 has this patched.

var j, sourceDoc, targetFile;

var destFolder = null;
// Get the destination to save the files
destFolder = Folder.selectDialog( 'Select the folder where you want to save the exported files.', '~' );

if (destFolder != null) {
  for ( j = 0; j < app.documents.length; j++ ) {
    sourceDoc = app.documents[ j ]; // returns the document object

    targetFile = getNewName(sourceDoc, destFolder);

    // set PNG export options
    var opt = new ExportOptionsPNG24();
    opt.antiAliasing = true;
    opt.transparency = true;

    // Export
    sourceDoc.exportFile(targetFile, ExportType.PNG24, opt);
  }
  alert( 'Files are saved as PNG24 in ' + destFolder );
}

function getNewName(sourceDoc, destFolder) {
  var docName = sourceDoc.name;
  var ext = '.png'; // new extension for png file
  var newName = "";

  // if name has no dot (and hence no extension,
  // just append the extension
  if (docName.indexOf('.') < 0) {
    newName = docName + ext;
  } else {
    var dot = docName.lastIndexOf('.');
    newName += docName.substring(0, dot);
    newName += ext;
  }

  // Create a file object to save the png
  saveInFile = new File( destFolder + '/' + newName );
  return saveInFile;
}
share|improve this answer

You can do it with inkscape's export option.

First install inkscape:

apt-get install inkscape

Create an export_to_png.sh script with the following code:

#!/bin/bash
for i in $(ls $1);
do
        inkscape -w100 -h100 -e $1/$i.png $1/$i
done

Make it executable:

chmod +x export_to_png.sh

Then run it:

./export_to_png.sh /path/to/images/

It will convert "somefile.ai" to "somefile.ai.png" with 100x100 size.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.