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

Save as PNG with transparency

Explorer ,
Jul 17, 2016 Jul 17, 2016

I'm trying to save a Photoshop file, changing the width and height to 50%, the resolution to 300, and keeping transparency. If I save as .png, it flattens the layers.

Saving as "Save for Web" works, but for some reason, it is changing the resolution to 72 and the width to 37in. If I open the image in Photoshop and change the resolution to 300, I get the correct width of 8.88in.

Here is what I have in the script. I'm new to javascript so bear with me.

var xMaxFullDimension=activeDocument.width.as('in');
var yMaxFullDimension=activeDocument.height.as('in');
activeDocument.resizeImage(new UnitValue(xMaxFullDimension*50/100,'in'), new UnitValue(yMaxFullDimension*50/100,'in'), 300, ResampleMethod.BICUBIC);

sfwPNG24(saveFile,100);

function sfwPNG24(saveFile,quality){

var pngOpts = new ExportOptionsSaveForWeb;

pngOpts.format = SaveDocumentType.PNG;

pngOpts.PNG8 = false;

pngOpts.transparency = true;

pngOpts.interlaced = false;

pngOpts.resolution=300;

pngOpts.quality = quality;

activeDocument.exportDocument(new File(saveFile),ExportType.SAVEFORWEB,pngOpts);

}

TOPICS
Actions and scripting
1.1K
Translate
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 , Jul 17, 2016 Jul 17, 2016

You can use just a normal save as rather than save for web to keep the 300 dpi. You can use scriptlistener to record all the code.

Translate
Adobe
Community Expert ,
Jul 17, 2016 Jul 17, 2016

Since this is save for web, the default web dpi is 72, so it changes the file to that, adjusting the length in inches. The pixel res remains the same. I'm not sure there is anything you can do.

Translate
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 17, 2016 Jul 17, 2016

You can use just a normal save as rather than save for web to keep the 300 dpi. You can use scriptlistener to record all the code.

Translate
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
Enthusiast ,
Jul 17, 2016 Jul 17, 2016

saveAs works like in Photoshop UI, ie. converts open document to new fileformat (which for PNG means flattening layers). But you can just duplicate the original doc and use saveAs on that and close it.

var tmp = original.duplicate("export_tmp")

tmp.saveAs(saveFile, pngOpts, false, Extension.NONE)

tmp.close(SaveOptions.DONOTSAVECHANGES)

Translate
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
Explorer ,
Jul 18, 2016 Jul 18, 2016

Chuck, I had tried just using the save function but it was flattening the file. I used the scriptListener and that solved my problem.

Matias, I tried your approach but it paused to ask for the file name. This is a batch process that is converting hundreds of covers.

Translate
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
Enthusiast ,
Jul 18, 2016 Jul 18, 2016

Add ​app.displayDialogs = DialogModes.NO

Translate
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
Explorer ,
Jul 19, 2016 Jul 19, 2016
LATEST

Thanks.

Translate
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