EMAIL ME WHEN AVAILABLE We will inform you when the product arrives in stock. Just leave your valid email address below.
Email Quantity We won't share your address with anybody else.

Microstock – Photoshop Scripting Batch Convert AI to JPG

A photoshop script written in javascript to batch convert your illustrator ai files into jpg. Useful when needing to create thumbnails, galleries or submit to microstock sites. If you are like me then you dislike mindless tasks and try to automate anything repetitious. With Microstock you can spend hours resizing and saving your images. What you may not know is that photoshop allows you to write script that automate these tasks.

Great Resources:

If you want to write your own scripts I recommend using Adobe”s ExtendScript Toolkit If you have the Adobe creative suite installed then you probably already have the Adobe ExtendScript Toolkit Installed. If not, then you can download it for free on the Adobe website.

Batch Convert AI to JPG

Here is a script I wrote to take your AI illustrator files in a folder and save them as large JPG files and thumbnails.
//----------------------------------------------------
// Illustrator to JPG Adobe Photoshop Javascript
// Created by Jaz Witham (Jazzerup)
// 2011
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND
// Script reads all your ai files from a folder and saves them as large JPG files and thumbnails
//----------------------------------------------------


// This also allows you to simply double click the JSX file
#target photoshop

// Save current dialog preferences
var startDisplayDialogs = app.displayDialogs;
var FILE_TYPE = ".ai"; // The type of files that this script works on -- you can change
var SEARCH_MASK = "*" + FILE_TYPE; // Image file filter to find only those files

// Set of exception strings for error handling
var X_NOINPUT = "noInput";
var X_BADDOC = "badDoc";
var X_WERROR = "writeError";
var X_CERROR = "closeError";

try {
  // Ask user for input folder
  var inputFolder = Folder.selectDialog("Select the folder with your ai files");
    var outputFolder = Folder.selectDialog("Select the folder to save your jpg files");
  if (inputFolder == null)
  throw X_NOINPUT;
     
var VarPrefRes = prompt("How many megapixels would you like your large files?", 20);  
var VarPrefResSmall = prompt("How many megapixels would you like your thumbnail files?", 1);     
     
function resizeimages(inputFolder,  outputFolder, VarPrefRes, varsize)   {  
    // get all files in the input folder
  var fileList = inputFolder.getFiles(SEARCH_MASK);

  // Open each file in turn
  for (var i = 0; i < fileList.length; i++) {
      // Only want to open non-hidden files (and no folders)
    if ((fileList[i] instanceof File) && (fileList[i].hidden == false)) {
          

      // Open the file in Photoshop to find out resolution
      var docRef = open( fileList[i]);
      if (docRef == null)
        throw X_BADDOC;
                
                app.preferences.rulerUnits = Units.PIXELS;
                var docRes = docRef.resolution;
                var docWidth = docRef.width.value/docRes;
                var docHeight = docRef.height.value/docRes;
                var  fname = docRef.name;
          
var varRes =((docHeight * docRes) * (docWidth * docRes))/1000000;  

//Ratio for resizing
var resratio = VarPrefRes/varRes;
var newresneeded =  Math.sqrt(VarPrefRes/varRes) * 300;

docRef.close(SaveOptions.DONOTSAVECHANGES);
                
        // Set the ruler units to pixels
        var pdfOpenOptions = new PDFOpenOptions
        pdfOpenOptions.antiAlias = true
        pdfOpenOptions.mode = OpenDocumentMode.RGB
        pdfOpenOptions.cropPage = CropToType.MEDIABOX
        pdfOpenOptions.suppressWarnings = true;
        pdfOpenOptions.resolution = newresneeded
        pdfOpenOptions.page = 1
        
        // Open the file in Photoshop
      var docRef = open( fileList[i], pdfOpenOptions );                
                       
        //save file
       myNewString = String(outputFolder + "/" + fname + "_" + varsize + ".jpg" );
       
        jpgFile = new File(myNewString)
        jpgSaveOptions = new JPEGSaveOptions()
        jpgSaveOptions.embedColorProfile = true
        jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE
        jpgSaveOptions.matte = MatteType.NONE
        jpgSaveOptions.quality = 12
        app.activeDocument.saveAs(jpgFile, jpgSaveOptions, true,
        Extension.LOWERCASE)

        // Close the Photoshop file
      docRef.close(SaveOptions.DONOTSAVECHANGES);
    }
    }
}

resizeimages(inputFolder,  outputFolder, VarPrefRes, "lrg")  
resizeimages(inputFolder,  outputFolder, VarPrefResSmall, "thumb")  


}
catch (exception) {
  // Show debug message and then quit
  alert(exception);
}
finally {
  // Reset app preferences
  app.displayDialogs = startDisplayDialogs;
}

Comments

comments

Trackback from your site.

jazzerup

This information box about the author only appears if the author has biographical information. Otherwise there is not author box shown. Follow YOOtheme on Twitter or read the blog.

Leave a comment

Jazzerup.com