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

Preserve Transparency when saving to PNG

Community Beginner ,
Jun 28, 2021 Jun 28, 2021

Copy link to clipboard

Copied

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!!

TOPICS
Actions and scripting

Views

801

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
Adobe
Community Expert ,
Jun 28, 2021 Jun 28, 2021

Copy link to clipboard

Copied

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? 

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 ,
Jun 29, 2021 Jun 29, 2021

Copy link to clipboard

Copied

Dupe post, I answered here this morning:

 

Photoshop script adding in a white layer unexpectedly

 

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 28, 2021 Jun 28, 2021

Copy link to clipboard

Copied

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);
}
 

```

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 28, 2021 Jun 28, 2021

Copy link to clipboard

Copied

missed this line from the top 

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

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 ,
Jun 28, 2021 Jun 28, 2021

Copy link to clipboard

Copied

Try adding to your ExportOptions:

 

opts.transparency = true;

 

You may also wish to consider making the script more portable:

 

var saveLocation = File("~/Dropbox/Mad Cat Militia/__GENERATED CATS__/cat.png");

 

 

 

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 ,
Jun 29, 2021 Jun 29, 2021

Copy link to clipboard

Copied

Duplicate post here:

 

Preserve Transparency when saving to PNG

 

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 ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

@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;

 

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 ,
Jul 09, 2021 Jul 09, 2021

Copy link to clipboard

Copied

LATEST

@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.

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