Illustrator PasteBoards to gif files Script

Illustrator PasteBoards to GIF files Script

Outputing the contents of Pasteboards from Illustrator as gif files in preparation to creating an animated GIF file.

// Define the GIF export options
var gifOptions = new ExportOptionsGIF();
gifOptions.colorReductionColorCount = 256;
gifOptions.colorReductionDither = ColorDitherMethod.NOISE;
gifOptions.colorReductionMethod = ColorReductionMethod.SELECTIVE;
gifOptions.ditherPercent = 50;
gifOptions.interlaced = false;
gifOptions.transparency = true;
// Loop through all artboards and export each one as a GIF file

for (var i = 0; i < app.activeDocument.artboards.length; i++) {
  // Set the active artboard
  gifOptions.artboardRange = i.toString();
  ExportOptionsGIF.artBoardClipping = true;
  // Set the file name for the GIF file
  var fileName = "c:\\Gif Files\\artboard" + (i + 1) + ".gif";
  // Export the active artboard as a GIF file
  app.activeDocument.exportFile(new File(fileName), ExportType.GIF, gifOptions);

The main option that will need to be changed on each system will be the location of the output folder. This was created on a Windows machine and the folder is "c:\\Gif Files\\artboard". This could be changed to be in the same location as the current Illustrator document. This can be achieved with:

var doc = app.activeDocument;
var filePath = doc.fullName;

The filePath will then need to be truncated to provide the folder name. Here is a routine to allow this to be done:

function getFolderName(filePath) {
  // Get the last index of the "/" character
  var lastSlashIndex = filePath.lastIndexOf("/");

  // Return the string up to the last "/" character (this will be the folder name)
  return filePath.substring(0, lastSlashIndex);

When the file is passed back from doc.fullName it is a device dependent path so this routine should work on both the Mac and Windows. So Macintosh HD:Gif (Mac) and c:\Gif Files\ would both be returned as /Macintosh HD/Gif Files/ and /c/Gif Files/

Combining the GIF files

Import your GIF files in Photoshop by clicking File > Import > Video Frames to Layers. Select all your frames from one of your GIFs and then copy them over into the video frames of the other GIF by clicking the Animation menu. This can be accomplished by selecting Window > Timeline or Window > Animation.

Contact info:


Popular posts from this blog

History of PDF

Illustrator Scripts for changing colors

Considerations for PDF Creation