Illustrator export script for efficient saving of images as web-friendly jpg files

Looking for assistance with creating a script in illustrator CC2017 that can automatically export files to web (legacy) as JPG, save the file, and then close it. I have 700 files, each with 2 art boards, and manually exporting and saving each one is time-consuming. Any suggestions or script recommendations would be greatly appreciated.

Answer №1

Here is the customized script based on your specifications. I have made adjustments to Script 1 to meet your requirements. It now assumes the ruler is in Points by default, converts it to inches, and incorporates it into the file name. Additionally, it includes logic to handle artboards beyond 26, displaying something different in that scenario. ASCII code is utilized for this purpose.

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 jpegFolder = Folder(currentFile.path + "/JPG");
        if (!jpegFolder.exists)
            jpegFolder.create();
        var codeStart = 97; // for a;
        for (var j = 0; j < activeDocument.artboards.length; j++) {
            var activeArtboard = activeDocument.artboards[j];
            activeDocument.artboards.setActiveArtboardIndex(j);
            var bounds = activeArtboard.artboardRect;
            var left = bounds[0];
            var top = bounds[1];
            var right = bounds[2];
            var bottom = bounds[3];
            var width = right - left;
            var height = top - bottom;
            if (app.activeDocument.rulerUnits == RulerUnits.Points) { //Add more if for more conversions
                width = width / 72;
                height = height / 72;
            }
            var fileName = activeDocument.name.split('.')[0] + "-" + String.fromCharCode(codeStart) + "-" + width + "x" + height + ".jpg";
            var destinationFile = File(jpegFolder + "/" + fileName);
            var type = ExportType.JPEG;
            var options = new ExportOptionsJPEG();
            options.antiAliasing = true;
            options.artBoardClipping = true;
            options.optimization = true;
            options.qualitySetting = 100; // Set Quality Setting
            activeDocument.exportFile(destinationFile, type, options);
            codeStart++;
        }
        activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        currentFile = null;
    }
}

Answer №2

If you're looking to convert all ai files in a specific folder into jpg format, the following javascript code will help you achieve that. This code prompts you to choose a folder containing 700 files.

Script 1: Using JPEGQuality

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 jpegFolder = Folder(currentFile.path + "/JPG");
        if (!jpegFolder.exists)
            jpegFolder.create();
        for (var j = 0; j < activeDocument.artboards.length; j++) {
            var activeArtboard = activeDocument.artboards[0];
            activeDocument.artboards.setActiveArtboardIndex(j);
            var fileName = activeDocument.name.split('.')[0] + "Artboard" + (j + 1) + ".jpg";
            var destinationFile = File(jpegFolder + "/" + fileName);
            var type = ExportType.JPEG;
            var options = new ExportOptionsJPEG();
            options.antiAliasing = true;
            options.artBoardClipping = true;
            options.optimization = true;
            options.qualitySetting = 100; // Set Quality Setting
            activeDocument.exportFile(destinationFile, type, options);
        }
        activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        currentFile = null;
    }
} 

Each ai file contains two artboards, resulting in two jpg files per file. You have the flexibility to customize file names and output folder locations according to your needs.

Script 2: By changing resolution

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 jpegFolder = Folder(currentFile.path + "/JPG");
        if (!jpegFolder.exists)
            jpegFolder.create();
        var fileName = activeDocument.name.split('.')[0] + ".jpg";
        var destinationFile = File(jpegFolder + "/" + fileName);
        // Export Artboard where you can set resolution for an image. Set to 600 by default in code.
        var opts = new ImageCaptureOptions();
        opts.resolution = 600;
        opts.antiAliasing = true;
        opts.transparency = true;
        try {
            activeDocument.imageCapture(new File(destinationFile), activeDocument.geometricBounds, opts);
        } catch (e) {

        }
        activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        currentFile = null;
    }
}

Script 2 generates only one jpg file per ai file, disregarding the artboards. Feel free to utilize both scripts to streamline your tasks.

Answer №3

This VBA example showcases the use of a specific Excel statement

Sub Export_All_Excel()
Dim fileSystem As Object
Dim illustratorRef As Object
Dim documentRef As Object
Dim jpegExportOptions As Object
Dim fileObj As Object
Dim path As String

    Set fileSystem = CreateObject("Scripting.FileSystemObject")
    Set illustratorRef = CreateObject("Illustrator.Application")
    Set jpegExportOptions = CreateObject("Illustrator.ExportOptionsJPEG")

    ' Set export options
    jpegExportOptions.AntiAliasing = False
    jpegExportOptions.QualitySetting = 70

    path = Application.ActiveWorkbook.Path

    For Each fileObj In fileSystem.GetFolder(path).Files
        If LCase(Right(fileObj.Name, 3) = ".ai") Then
            Debug.Print fileObj.Name
            Set documentRef = illustratorRef.Open(path + "\" + fileObj.Name)
            Call documentRef.Export(path + "\" + fileObj.Name + ".jpg", 1, jpegExportOptions)
            Set documentRef = Nothing
        End If
    Next

    ' Illustrator remains open but invisible
End Sub

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a character jump animation on an HTML5 canvas

While following a tutorial on creating character animations, I encountered an issue. The tutorial, located at , made it easy to make the character move left (the right movement was already implemented). However, I am struggling with how to animate the char ...

Node.js server experiencing delays handling multiple requests causing timeouts

As someone who is not very experienced with node, I appreciate your patience. I have a node.js server with 2 routes. Throughout the day, both routes receive requests simultaneously. Route 1 runs smoothly, while route 2 is a long-running process that invol ...

Embedding SVG styling directly into the HTML document

When importing svg images with color into Mapbox Studio, they appear as black and white. The troubleshooting website mentions: If your SVG appears black after adding to Mapbox Studio, it may be due to using style properties in tags instead of inline sty ...

Node.js is known for its unreliable promise returns

Currently, I have a function in place that establishes a connection with a sql database. After querying the database and formatting the results into an HTML table, the function returns the variable html: function getData() { return new Promise((resolv ...

The alert function is not being triggered upon receiving a JSON response

I am having trouble with an alert not firing a json response. The response appears in firebug, but after upgrading from php4.4.7 to php5.3.5, I encountered this error. It could be my mistake as well. Could someone please review my code and point out where ...

Pressing the tab key makes all placeholders vanish

case 'input': echo '<div class="col-md-3"> <div class="placeholder"> <img src="images/person.png" /> &l ...

Tips on deleting CSS comments from a CSS file

Currently, I am utilizing nextjs + reactjs. My objective is to eliminate all CSS comments from my existing css file. Despite using next-purgecss in order to get rid of unnecessary CSS code, the comments are still persisting. What could be the reason behind ...

What is the best way to show a macOS progress pie loading icon alongside files?

While using macOS, a pie loading icon appears next to a file during downloading or transferring. To illustrate, here is an example of a file being downloaded from Chrome: https://i.sstatic.net/8jS4X.png I am interested in implementing a similar feature i ...

Learn the process of covering the entire screen with a video

I'm attempting to achieve this: IMG Below is the code snippet I've been using: <div class="container" id="containervideo"> <div id="video"> <div class="box iframe-box"> <div class="container"> ...

To prevent the background window from being active while the pop-up is open

I have a link on my webpage that triggers a pop-up window, causing the background to turn grey. However, I am still able to click on other links in the background while the pop-up is open. I tried using the code document.getElementById('pagewrapper&ap ...

Angular Reactive Forms may not properly update other inputs when binding a control to multiple inputs

While working with reactive forms, I encountered an issue where accessing the same control in multiple inputs seemed to result in one-way data binding (input-to-model). If I make edits in one input, it updates the model correctly but does not refresh the o ...

"Utilize the power of the ajaxform jQuery plugin to automatically reset form fields

Initially, I'd like to emphasize that this is an original inquiry. My predicament is as follows: I have a chatroom php script where I utilize the ajaxForm jQuery plugin to seamlessly send new messages without having to reload the entire page. Howev ...

Searching for various object values within an array and then adding two properties together in JavaScript

I am working with an array of objects that require me to analyze two properties in order to calculate a value. let data = [ { NodeId: "9837f279", NodeName: "Node1", summary: { current: 50, limit: 75 ...

Retrieving data with model.fetch in Backbone.js when the server response is null

In my app, we utilize model.fetch() to retrieve JSON from the server. The render function is triggered when the model undergoes a change and looks like this: if(_.isUndefined(this.model.get("id_number"))){ this.template = initialTemplate; } else if(th ...

Achieving Efficiency with Handlebars: Streamlining Remote Template Organization and

I am looking for a way to better organize my HB template by splitting it into different HTML files. In this case, I have created a file called helpers.html. This file contains two script tags: <script id='alert' type='text/template>... ...

Create a custom slider using jQuery that pulls in real-time data for a dynamic user

My goal is to implement a dynamic slider feature in my Django project by using jQuery and ajax. I have managed to create previous and next buttons for swiping through profiles with the help of others, but I am currently facing an issue with a NoReverseMatc ...

Is it possible to utilize npm request multiple times within a single route and showcase the outcomes on a single page?

Is it possible to utilize the node module "request" multiple times within a single route, and have the outcomes presented on a solitary rendered ejs template page? Objective: The aim is to exhibit eBook details from the iTunes Store by utilizing their Sea ...

<a href> click here to append a new query parameter to the existing ones

Is there a way to create a link that will add a query parameter to the current URL instead of replacing all existing ones? Here's what I'm looking for: If the current URL in the browser is example.com/index.html, clicking on it should lead to ...

Guide on printing in an Ionic application using print.js without the need to open the printer setup page

Our team is currently working on an Ionic web application that utilizes printer functionality. To enable printing, we have integrated the Print.js npm package. However, when we initiate the print method, a setup page displaying details such as printer na ...

Issue with Laravel: Using `$request->all()` results in an empty array when called using JSON XHR

Having trouble using $.ajax and only the XMLHttpRequest for sending JSON to a Laravel controller. Keep getting 500 errors when attempting to make the request. Here's the method I'm using to send the data: const sendEdit = function(){ ...