• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

script to save as png

Participant ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Is there any script to save illustrator file to png in same directory. once saved AI file should be closed without saving. Also file naming of PNG should be as per AI file. please help me on this

resolution on png: 72

 

TOPICS
Scripting

Views

6.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 01, 2020 May 01, 2020

Hi, 
While exporting PNG via script, it is not possible to give resolution when exporting AI document either by ExportOptionPNG8 or ExportOptionsPNG24. For reference please see below screenshot

 

PNGOptions.png

 

But you can use option ImageCaptureOptions to export AI document into png while specifying the resolution. See below screenshot.

 

imageCapture.png

 

So, for your problem solution will be,

 

function saveAsPNG() {
    var pngFile = new File(app.activeDocument.path + "/" + app.activeDocument.name.split('.')[0] + '.png');
    va
...

Votes

Translate

Translate
Adobe
Community Expert ,
May 01, 2020 May 01, 2020

Copy link to clipboard

Copied

Hi, 
While exporting PNG via script, it is not possible to give resolution when exporting AI document either by ExportOptionPNG8 or ExportOptionsPNG24. For reference please see below screenshot

 

PNGOptions.png

 

But you can use option ImageCaptureOptions to export AI document into png while specifying the resolution. See below screenshot.

 

imageCapture.png

 

So, for your problem solution will be,

 

function saveAsPNG() {
    var pngFile = new File(app.activeDocument.path + "/" + app.activeDocument.name.split('.')[0] + '.png');
    var resolution = 72;
    var opts = new ImageCaptureOptions();
    opts.resolution = resolution;
    opts.antiAliasing = true;
    opts.transparency = true;
    try {
        app.activeDocument.imageCapture(pngFile, app.activeDocument.geometricBounds, opts);
        app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    } catch (e) {

    }
}

saveAsPNG();

 

You can change value of resolution here as per your requirements.

Let us know if this helps you.

 

Thanks

Charu

Best regards

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 02, 2021 Jun 02, 2021

Copy link to clipboard

Copied

Hi,

 

Great script, thank you!

I have 2 requests, if possible:

1. Is there a way to add an option to save the PNG as a clipped artbourd? I have Illustrator files with content outside the artboard an when using the script the saved image is showing all content not the artboard itself.

I tried to add a line:

opts.artBoardClipping = true;

but no results, the image saved contains entire file content no clipped to artboard.

 

and 
2. Is there a way to add an option to save the file in a different size from the original Illustrator artboard? For example I have files at 850x1134 px and I want to save PNGs as 1500x2000 px

Can be done with scripting? Maybe by using scaling in percentage (e.g. saved at 150%) or by using absolute values (e.g. 1500x2000 px).

 

Looking forward for your ideas 🙂

 

Best,

Adrian

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 03, 2021 Jun 03, 2021

Copy link to clipboard

Copied

function saveAsPNG() {
    var pngFile = new File(app.activeDocument.path + "/" + app.activeDocument.name.split(".")[0] + ".png");
    var type = ExportType.PNG24;
    var opts = new ExportOptionsPNG24();
    opts.antiAliasing = false;
    opts.transparency = false;
    opts.artBoardClipping = true;
    opts.horizontalScale = 150;
    opts.verticalScale = 150;
    try {
        app.activeDocument.exportFile(pngFile, type, opts);
        app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
    } catch (e) {}
}
saveAsPNG();

(But, as @Charu Rajput said, you cannot change the resolution now.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 03, 2021 Jun 03, 2021

Copy link to clipboard

Copied

Thank you! Works for me this way 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 14, 2021 Sep 14, 2021

Copy link to clipboard

Copied

Hi Charu,

I have tried "saveAsPNG" script as per above and it works fine as well. Is that any option to include Clip artboard or enabling "use Artboards" selection while exporting PNG in the above script.

I have used "opts.artBoardClipping = true;" in the above but it doesnt work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 05, 2023 Jan 05, 2023

Copy link to clipboard

Copied

Hello ! Excuse me, what is:

app.activeDocument.geometricBounds

for? thanks!

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 05, 2023 Jan 05, 2023

Copy link to clipboard

Copied

@AntonioPacheco ,

imageCapture (imageFile:File, [clipBounds:Rect], [options:ImageCaptureOptions])

clipBounds ->  The rectangular region of the artwork for image capture. If the parameter is omitted, the entire artwork bound is captured.

Best regards

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 05, 2023 Jan 05, 2023

Copy link to clipboard

Copied

LATEST

Alright so that means it captures and export the size of the artboard? sorry for bothering. If it does so, how can I do to capture only the area of the design / vector / draw and not the artboard?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines