Skip navigation
Currently Being Moderated

Need script to batch convert vector .eps to .png images with scale

Nov 29, 2011 6:15 AM

Tags: #with #resizing #script #images #batch #to #convert #vector #resize #need #.eps #.png

Hi,

 

I'm looking for a script/program that if you run it, all the .eps files in a folder will batch convert to a png-24 with 250% scale.

 

Erdem

 
Replies
  • Currently Being Moderated
    Nov 29, 2011 9:42 AM   in reply to Snuurtje
    /**********************************************************
    
    ADOBE SYSTEMS INCORPORATED 
    Copyright 2005 Adobe Systems Incorporated 
    All Rights Reserved 
    
    NOTICE:  Adobe permits you to use, modify, and 
    distribute this file in accordance with the terms
    of the Adobe license agreement accompanying it.  
    If you have received this file from a source 
    other than Adobe, then your use, modification,
    or distribution of it requires the prior 
    written permission of Adobe. 
    
    *********************************************************/
     
    /**********************************************************
    
    Save as PDFs.js
    
    DESCRIPTION
    
    This sample gets files specified by the user from the 
    selected folder and batch processes them and saves them 
    as PDFs in the user desired destination with the same 
    file name.
    
    **********************************************************/
     
    // Main Code [Execution of script begins here]
     
    // uncomment to suppress Illustrator warning dialogs
    // app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
     
    var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, pngExportOpts;
     
    // Select the source folder.
    sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to convert to PNG', '~' );
     
    // If a valid folder is selected
    if ( sourceFolder != null )
    {
        files = new Array();
        fileType = prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', ' ' );
        
        // Get all files matching the pattern
        files = sourceFolder.getFiles( fileType );
        
        if ( files.length > 0 )
        {
            // Get the destination to save the files
            destFolder = Folder.selectDialog( 'Select the folder where you want to save the converted PNG files.', '~' );
            for ( i = 0; i < files.length; i++ )
            {
                sourceDoc = app.open(files[i]); // returns the document object
                                        
                // Call function getNewName to get the name and file to save the pdf
                targetFile = getNewName();
                
                // Call function getPNGOptions get the PNGExportOptions for the files
                pngExportOpts = getPNGOptions();
                
                // Export as PNG
                sourceDoc.exportFile( targetFile, ExportType.PNG24, pngExportOpts );
                
                sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
            }
            alert( 'Files are saved as PNG in ' + destFolder );
        }
        else
        {
            alert( 'No matching files found' );
        }
    }
     
     
     
     
    /*********************************************************
    
    getNewName: Function to get the new file name. The primary
    name is the same as the source file.
    
    **********************************************************/
     
    function getNewName()
    {
        var ext, docName, newName, saveInFile, docName;
        docName = sourceDoc.name;
        ext = '.png'; // new extension for png file
        newName = "";
            
        for ( var i = 0 ; docName[i] != "." ; i++ )
        {
            newName += docName[i];
        }
        newName += ext; // full png name of the file
        
        // Create a file object to save the png
        saveInFile = new File( destFolder + '/' + newName );
        
     
        return saveInFile;
    }
     
     
     
     
    /*********************************************************
    
    getPNGOptions: Function to set the PNG saving options of the 
    files using the PDFSaveOptions object.
    
    **********************************************************/
     
    function getPNGOptions()
    {
        
        // Create the PDFSaveOptions object to set the PDF options
        var pngExportOpts = new ExportOptionsPNG24();
        
        
        
        // Setting PNGExportOptions properties. Please see the JavaScript Reference
        // for a description of these properties.
        // Add more properties here if you like
        pngExportOpts.antiAliasing = true;
        pngExportOpts.artBoardClipping = true;
        pngExportOpts.horizontalScale = 250.0;
        //pngExportOpts.matte = true;
        //pngExportOpts.matteColor = 0, 0, 0;
        pngExportOpts.saveAsHTML = false;
        pngExportOpts.transparency = false;
        pngExportOpts.verticalScale = 250.0;
     
        return pngExportOpts;
    }
    
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 21, 2012 7:05 AM   in reply to Larry G. Schneider

    That worked well!

     

    How would I modify that script to:

     

    retain the same file name;

    convert all the files in selected folder;

    and not select only the artboard?

     

    Is that possible?

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 21, 2012 8:43 AM   in reply to Steph Lovering

    pngExportOpts.artBoardClipping = false;

     

    pngExportOpts.horizontalScale = 100.0;

     

    pngExportOpts.verticalScale = 100.0;

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 21, 2012 8:55 AM   in reply to Steph Lovering

    Woops!

     

    Duh: pngExportOpts.artBoardClipping = false;

     

    Turns out that script already does that, but my files were names with multiple '.' so it kept overwriting the same file.

    Ex. 2.1.1.1 Image.eps --> 2.png

          3.1.1.2 Image.eps --> overwritten

          3.1.1.3 Image.esp --> 3.png

     

    Changed the script to:

     

    function getNewName()

    {

        var ext, docName, newName, saveInFile, docName;

        docName = sourceDoc.name;

        ext = '.png'; // new extension for png file

        newName = "";

          

    //    for ( var i = 0 ; docName[i] != "." ; i+ )

    //    {

    //        newName += docName[i];

    //    }

        newName = docName + ext; // full png name of the file

      

        // Create a file object to save the png

        saveInFile = new File( destFolder + '/' + newName );

     

     

        return saveInFile;

    }

     

     

     

     

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 21, 2012 9:12 AM   in reply to Muppet Mark

    Thank you!

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 22, 2012 9:20 AM   in reply to Steph Lovering

    Is it possible to tell the script to convert all the folders in that directory? Or to change the .dpi of the .png?

    (Can you tell I'm new at using scripts!)

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 22, 2012 9:41 AM   in reply to Steph Lovering

    1. Yes its possible to resurse all the sub folders and get the files of each…

    2. No AI will not let you adjust the dpi its 72 but you can set the scale percentages to get the required pixel counts… Change the res in Photoshop if you have it…?

    ( I think the other way would have been most users preference )

    3. That don't matter we all were at some point or other…

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 22, 2012 9:42 AM   in reply to Steph Lovering

    The DPI of PNG files saved from a script will always be 72. You can scale the file (416.6 %) will give the equivalent of 300 DPI when resized to the original size but other than that, no.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 9, 2012 2:45 PM   in reply to Larry G. Schneider

    I get this error, any idea why?

    Error 22: ExportOptionsPNG24 does not have a constructor.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 9, 2012 3:17 PM   in reply to DominionKid

    I have no clue what the error refers to. How are you using the script?

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 17, 2012 2:01 PM   in reply to Larry G. Schneider

    Is there a way to also crop to artwork after exporting to artboard in the same routine?

     

    I have a tag outisde the artboard and I get easily get rid of it with this command

     

       pngExportOpts.artBoardClipping = true

     

     

    but I would like to also crop to work area at the same time,

     

    is it possible to?

     

     

    Thanks very much in advance!

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 25, 2012 12:05 PM   in reply to Pippo.B

    That is a wonderful script.  I've finally figured out how to impliment it, and it works great.

     

    I was just wondering if there was a way to modify it to preserve transparency?  I'm using it to convert WMF to PNG, and would like to preserve the transparency.

     

    Thanks.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 25, 2012 12:14 PM   in reply to 9thReg

    Change this line

     

    pngExportOpts.transparency = false;

     

    to

     

    pngExportOpts.transparency = true;

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 25, 2012 12:19 PM   in reply to Larry G. Schneider

    Thank you so much.  It worked perfectly.  Thanks again.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 25, 2012 1:54 PM   in reply to Muppet Mark

    Hi, may I ask how to resurse all the subfolders and get the files of each.

    I tryed but no luck, it still doesn't include all subfolders.

     

    Anyone can help me with that, I'd appreciate a lot.

     

    Thanks.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 12, 2012 7:01 AM   in reply to Larry G. Schneider

    I am getting the following error:

     

    Error 24: getNewName is not a function

    Line: 27

     

    Below is the complete code (I bolded the error section (I simply copied both sections of the main article.  I am very new to scripting...).  I do a ton of converting from .eps and .ai to transparent PNG so this would be a HUGE help:

     

    // uncomment to suppress Illustrator warning dialogs

    // app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

     

    var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, pngExportOpts;

     

    // Select the source folder.

    sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to convert to PNG', '~' );

     

    // If a valid folder is selected

    if ( sourceFolder != null )

    {

        files = new Array();

        fileType = prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', ' ' );

       

        // Get all files matching the pattern

        files = sourceFolder.getFiles( fileType );

       

        if ( files.length > 0 )

        {

            // Get the destination to save the files

            destFolder = Folder.selectDialog( 'Select the folder where you want to save the converted PNG files.', '~' );

            for ( i = 0; i < files.length; i++ )

            {

                sourceDoc = app.open(files[i]); // returns the document object

                                       

                // Call function getNewName to get the name and file to save the pdf

                targetFile = getNewName();

               

                // Call function getPNGOptions get the PNGExportOptions for the files

                pngExportOpts = getPNGOptions();

               

                // Export as PNG

                sourceDoc.exportFile( targetFile, ExportType.PNG24, pngExportOpts );

               

                sourceDoc.close(SaveOptions.DONOTSAVECHANGES);

            }

            alert( 'Files are saved as PNG in ' + destFolder );

        }

        else

        {

            alert( 'No matching files found' );

        }

    }

    function getPNGOptions()

    {

       

        // Create the PDFSaveOptions object to set the PDF options

        var pngExportOpts = new ExportOptionsPNG24();

       

       

       

        // Setting PNGExportOptions properties. Please see the JavaScript Reference

        // for a description of these properties.

        // Add more properties here if you like

        pngExportOpts.antiAliasing = true;

        pngExportOpts.artBoardClipping = true;

        pngExportOpts.horizontalScale = 250.0;

        //pngExportOpts.matte = true;

        //pngExportOpts.matteColor = 0, 0, 0;

        pngExportOpts.saveAsHTML = false;

        pngExportOpts.transparency = true;

        pngExportOpts.verticalScale = 250.0;

     

        return pngExportOpts;

    }// JavaScript Document

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 12, 2012 9:19 AM   in reply to DNK1515

    Look at the posted original file again. You are missing the function getNewName which is in the original version I posted.

     
    |
    Mark as:
  • Currently Being Moderated
    May 23, 2013 7:04 AM   in reply to Larry G. Schneider

    Hi,

     

    Just wanted to thx you for the Qeustion and Script... Just what i was looking for ...

    THX a MILL !!!

     

    Robert

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points