Skip to main content
Participant
June 28, 2021
Question

Preserve Transparency when saving to PNG

  • June 28, 2021
  • 5 replies
  • 1427 views

Hi all, 

 

I am running a script on photoshop that pulls in png files as layers and saves as a png. Problem is the transparency of the layers is not being preserved and we are seeing white corners on our rounded images.

 

I urgently need some help as we have loads to generate and a tight timeframe!

Code:

```

var saveLocation = File("/Users/user/Dropbox/Mad Cat Militia/__GENERATED CATS__/cat.png");
var opts;
opts = new ExportOptionsSaveForWeb();
opts.format = SaveDocumentType.PNG;
opts.PNG8 = false;
opts.quality = 100;
 
app.activeDocument.exportDocument(saveLocation, ExportType.SAVEFORWEB, opts);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

```

Thankyou!!

This topic has been closed for replies.

5 replies

Stephen Marsh
Community Expert
Community Expert
July 10, 2021

@defaultydc8bdl53b6t 

 

Did adding the line of code that I suggested resolve this issue?

 

Please add likes and or correct answers to the various posts so that when others are searching for a resolution to their issue it will be obvious that a solution was found.

Stephen Marsh
Community Expert
Community Expert
June 30, 2021

@defaultydc8bdl53b6t 

 

It looks like a moderator has merged/combined the two separate topics into a single one... So, did adding this code work?

 

I'm going to remove the correct answer that was applied to my dupe post message.

 

opts.transparency = true;

 

Stephen Marsh
Community Expert
Community Expert
June 29, 2021

Dupe post, I answered here this morning:

 

Photoshop script adding in a white layer unexpectedly

 

c.pfaffenbichler
Community Expert
Community Expert
June 29, 2021

Why haven’t you posted one of the images? 

 

Edit: I apologize, I had misread and you did use png24. 

Could you please post screenshots of the original image taken at View > 100% and the resulting png? 

Participant
June 28, 2021

Hi, 

 

I am generating a png file from multiple png files as layers. Output is showing white corners (image has rounded ones) and it seems as if a white layer is being added in the generation.

REALLY APPRRECIATE any help - we are really up against it!

Any ideas why that woud be happening here:

```

for (var i = 0; i < items.length; i++) {
if (items[i]) {
 
var doc = open(items[i]);
var layer = doc.activeLayer;

layer.name = layerNames[i];
layer.duplicate(document, ElementPlacement.PLACEATBEGINNING);

// close imported document
doc.close(SaveOptions.DONOTSAVECHANGES);
}
}

var saveLocation = File("/Users/user/Dropbox/Mad Cat Militia/__GENERATED CATS__/cat.png");
var opts;
opts = new ExportOptionsSaveForWeb();
opts.format = SaveDocumentType.PNG;
opts.PNG8 = false;
opts.quality = 100;
 
app.activeDocument.exportDocument(saveLocation, ExportType.SAVEFORWEB, opts);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
 

```

Participant
June 28, 2021

missed this line from the top 

for (var j = 0; j < cats.length; j++) {
var document = app.documents.add(5000, 5000, 72, "Cat" + j);