PDA

View Full Version : Export png24 from Illustrator with white background


booder101
10-08-2009, 03:51 PM
Hello, I think this there is a simple solution, I just cannot find it. I want to export a layer of Illustrator with a white background. I am able to export the layer, but it has a transparent background. I got the basic code off the internet and just changed options.transparency = false but this does not do the trick. Greatly appreciate any help - I have looked thru Javascript/actionscript reference guides searching for setting background to white but have not had luck.. Thank you!
=-======================

script follows:
/**
* @author Niels Bosma ([email protected]
*/

var folder = Folder.selectDialog();
var document = app.activeDocument;
if(document && folder)
{
var options = new ExportOptionsPNG24();
options.antiAliasing = true;
options.transparency = false;

var n = document.layers.length;
for(var i=0; i<n; ++i)
{
hideAllLayers();
var layer = document.layers[i];
layer.visible = true;

var file = new File(folder.fsName+"/"+layer.name+".png");

var options = new ExportOptionsPNG24();
options.artBoardClipping = true;

document.exportFile(file,ExportType.PNG24,options) ;


}

showAllLayers();
}

function hideAllLayers()
{
forEach(document.layers, function(layer) {
layer.visible = false;
});
}

function showAllLayers()
{
forEach(document.layers, function(layer) {
layer.visible = true;
});
}

function forEach(collection, fn)
{
var n = collection.length;
for(var i=0; i<n; ++i)
{
fn(collection[i]);
}
}

elytexeira
10-10-2009, 12:34 AM
PNG supports transparency. So one solution could be changing the setup in your illustrator file. There you could change the background to white instead of transparent.


---------------------
currently working at : http://www.probooks.com.mx

booder101
10-11-2009, 10:35 AM
Thank you for your reply. I did try changing the background color in Illustrator to white - but it only displays as white, but does not export as white (since there is no real white rectangle in the background). I can't create a white rectangle to be the background because I have many separate layers in my Illustrator file so I would have to create that background many times.

When exporting to png from Illustrator, it does prompt for Background color - giving options for Transparent, White, Black, Custom. Is there a way to access or assign the background color for the exported layer through scripting there?
Appreciate any help.