Skip to main content
Inspiring
January 22, 2018
Answered

Script for scaling Illustrator file to png => scaling option?

  • January 22, 2018
  • 1 reply
  • 2042 views

Hello

Below, see my script for scaling an Illustrator file to a png file. I have just a question about the scaling options for the png. If I have a graphic and I need to export to a dimension of 144x144 dpi, which value do I have to insert in line 83 and 88. Now, I tested, but I think the value is incorrect. There are experienced users here who have more experience then I have. I read that the values means scaling to a percentage. So, I should say if you export to a png that the standard value is 72 dpi and that you have to set the value to 200. But I experienced in other applications that the png metadata does not say that the resolution is 144 dpi but gives another value.

Hope somebody can help me...

#target illustrator

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

// Select the source folder.

sourceFolder = Folder.selectDialog( 'Select the folder with all files that have to be converted to a PNG', '~' );

// If the folder is selected, then ....

if ( sourceFolder != null )

{

    files = new Array();

    fileType = prompt( 'Which type of files would you like to convert to PNG? Example how to input: *.ai', ' ' );

  

    // check if all files have the right extension like described above.

    files = sourceFolder.getFiles( fileType );

  

    if ( files.length > 0 )

    {

        // select the destination folder where the png files have to be saved

        destFolder = Folder.selectDialog( 'Select the folder where the converted PNG files have to be saved.', '~' );

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

        {

            sourceDoc = app.open(files); // 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( 'The converted PNG files are saved in following folder: ' + destFolder );

    }

    else

    {

        alert( 'No files founded!' );

    }

}

/*********************************************************

getNewName: Function to get the new file name. The primary

name is the same as the source file.

Functie om de nieuwe filenaam te genereren. De oorspronkelijke naam wordt gebruikt (zonder extensie)

**********************************************************/

function getNewName()

{

    var ext, docName, newName, saveInFile, docName;

    docName = sourceDoc.name;

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

    newName = "";

      

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

    {

        newName += docName;

    }

    newName += ext; // full name of the new file including the png extension

  

    // create the new file with the corrected extension

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

    return saveInFile;

}

/*********************************************************

getPNGOptions: Function to set the PNG saving options of the

files using the PDFSaveOptions object.

Hier worden de PNG opties beschreven (= als je een opslaan als selecteert, welke opties je aanvinkt en uitvinkt.

**********************************************************/

function getPNGOptions()

{

  

    // Hier worden de PNG opties beschreven (= als je een opslaan als selecteert, welke opties je aanvinkt en uitvinkt.

    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 = false;

    pngExportOpts.horizontalScale = 200;

    //pngExportOpts.matte = true;

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

    pngExportOpts.saveAsHTML = false;

    pngExportOpts.transparency = true;

    pngExportOpts.verticalScale = 200;

    return pngExportOpts;

}

This topic has been closed for replies.
Correct answer OMOTI

Hi, jessevictoor.

Is this article your helpful?

https://helpx.adobe.com/illustrator/using/exporting-artwork.html

---------------------------------

PNG export options

...

Resolution

Determines the resolution of the rasterized image. Higher resolution values result in better image quality but larger file sizes.

note: Some applications open PNG files at 72 ppi, regardless of the resolution you specify. In such applications, the dimensions of the image will be altered. (For example, artwork saved at 150 ppi will be over twice as large as artwork saved at 72 ppi.) Therefore, only change the resolution when you know the target application supports non‑72‑ppi resolutions.

1 reply

OMOTI
OMOTICorrect answer
Inspiring
January 22, 2018

Hi, jessevictoor.

Is this article your helpful?

https://helpx.adobe.com/illustrator/using/exporting-artwork.html

---------------------------------

PNG export options

...

Resolution

Determines the resolution of the rasterized image. Higher resolution values result in better image quality but larger file sizes.

note: Some applications open PNG files at 72 ppi, regardless of the resolution you specify. In such applications, the dimensions of the image will be altered. (For example, artwork saved at 150 ppi will be over twice as large as artwork saved at 72 ppi.) Therefore, only change the resolution when you know the target application supports non‑72‑ppi resolutions.

Inspiring
January 23, 2018

Thx for info.

Some additional info, the scripting information about th vertical and horizontal scaling are in percentages.

If you do it manually by using the command: File > export as > there it is in dpi :-s

Strange adobe strategic....