Skip to main content
nickg2021
Participating Frequently
December 1, 2009
Question

How do I script a PNG24 file to have white opaque background

  • December 1, 2009
  • 1 reply
  • 1595 views

I have a script that will export layers to png files but I want each layer to have a white background and not a transparent background

I am using these sets of export options.

var exportOptions = new ExportOptionsPNG24();

exportOptions.antiAliasing = true;

exportOptions.matte = true;

exportOptions.matteColor = RGBColorobject;

exportOptions.transparency = false;

I know I am using the exportOptions.matteColor = RGBColorobject; incorrectly but need some direction on how to get this to work.

even when I delete that line and have the transparency set to false and the matte = true I still get a transparent background.
Any coaching will be appreciated.

This topic has been closed for replies.

1 reply

Larry G. Schneider
Community Expert
Community Expert
December 1, 2009

Delete the matte color line and try setting artBoardClipping to true.

nickg2021
nickg2021Author
Participating Frequently
December 1, 2009

Thanks for responding Larry,

I did that and when I open the png file in photoshop it still has a transparent background.

usually transparent backgrounds would be great but I need to isolate some patterns to be used on a 3D model in PS CS4

All the references I see say to just mark transparency as false…

Nick

Participating Frequently
December 5, 2009

Thanks!

Very close but now I want to apply it to all the layers not just the layer selected.

But I can see how you get the flattened file.

So the best analogy I can reach is that each layer is like a sheet of acetate with art on it.

And trying to make an opaque white artboard as a catch-all would not work.

Instead you have to take each layer and flatten it before export. Then address the script to do the same for each additional layer in a document until it comes to the end of the layers?

Again thanks for the help!

Nick


well you can do something like this ...though  i`m quite out of the subject on this one:

var doc = app.activeDocument;

var docRef = app.documents.add();

app.activeDocument = doc;

for(j = doc.pageItems.length - 1; j>=0; j--){

     //not quite sure if it gets as pageItem, pathItems inside CopoundPaths for example;

     if(doc.pageItems.parent.typename == "Layer") doc.pageItems.duplicate(docRef);

}

//(********* CODE CREDITS GO TO Muppet Mark ********)

var userHome = Folder("~").fsName.toString();

var fileRef = new File (userHome + '/Desktop/Marks_Star.png');

exportAsPNG24File(fileRef, 'Flat');

function exportAsPNG24File(saveFile, x) {

var exportType = ExportType.PNG24;

var png24Options = new ExportOptionsPNG24();

with (png24Options) {

switch(x) {

case 'Flat' :

transparency = false;

var bgMatte = new RGBColor();

bgMatte.red = 255; bgMatte.green = 255; bgMatte.blue = 255;

matte = true;

matteColor = bgMatte; break;

case 'Tran' :

matte = false;

transparency = true; break;

}

antiAliasing = true;

artBoardClipping = true;

horizontalScale = 100;

saveAsHTML = false;

verticalScale = 100;

}

docRef.exportFile(saveFile, exportType, png24Options);

}

hope itsomehow helps;

cheers;