Illustrator Artboards to GIF files Script

artboards to gifs illustrator script

Outputing the contents of Artboards from Illustrator as gif files in preparation to creating an animated GIF file written in an ExtendScript Illustrator Script.

				
					// 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
app.activeDocument.artboards.setActiveArtboardIndex(i);
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 in this Illustrator script on your 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 Files:Test.ai(Mac) and c:Gif FilesTest.ai would both be returned as /Macintosh HD/Gif Files/Test.ai and /c/Gif Files/Test.ai 

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.
Share the Post:

Related Posts

Join Our Newsletter

Illustrator Artboards to GIF files Script

artboards to gifs illustrator script

Outputing the contents of Artboards from Illustrator as gif files in preparation to creating an animated GIF file written in an ExtendScript Illustrator Script.

				
					// 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
app.activeDocument.artboards.setActiveArtboardIndex(i);
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 in this Illustrator script on your 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 Files:Test.ai(Mac) and c:Gif FilesTest.ai would both be returned as /Macintosh HD/Gif Files/Test.ai and /c/Gif Files/Test.ai 

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.
Share the Post:

Related Posts

Join Our Newsletter