Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Photoshop script ignores transparency on saving into png (Mac OS)

For example I have a project with two layers. First layer is transparent. Second layer has a rect and its opacity is 50%.

After saving in a saved file the picture looks like as the opacity was 100% (fully opaque). How to solve this? I used the following function to save:

function SavePNG(saveFile){
    var opts = new ExportOptionsSaveForWeb();
    opts.format = SaveDocumentType.PNG;
    opts.PNGB = false;
    opts.quality = 100;
    pngFile = new File(saveFile);
    opts.includeProfile = true;
    app.activeDocument.exportDocument(pngFile, ExportType.SAVEFORWEB, opts);
}

I used photoshop cs6

like image 808
user2412679 Avatar asked Dec 06 '25 14:12

user2412679


2 Answers

I have found a solution in photoshop forums:

function SavePNG(saveFile){
    pngFile = new File(saveFile);

    var pngOpts = new ExportOptionsSaveForWeb; 
    pngOpts.format = SaveDocumentType.PNG
    pngOpts.PNG8 = false; 
    pngOpts.transparency = true; 
    pngOpts.interlaced = false; 
    pngOpts.quality = 100;
    activeDocument.exportDocument(pngFile,ExportType.SAVEFORWEB,pngOpts);
}

At least this solution hasn't problems with transparency and works automatically without of showing dialogs

like image 65
user2083364 Avatar answered Dec 08 '25 09:12

user2083364


Try adding this to the list of options

opts.transparency = true

Okay, try ExportOptionsSave

    function SavePNG(saveFile)
{
    var pngFile = new File(filePath);
    opts = new PNGSaveOptions();
    opts.format = SaveDocumentType.PNG;
    opts.transparency = true
    opts.PNGB = false;
    opts.quality = 100;
    opts.includeProfile = true;

    activeDocument.saveAs(pngFile, opts, false, Extension.LOWERCASE);
}

I normally use something along these line:

// call the source document
var srcDoc = app.activeDocument;
var fileName = app.activeDocument.name;
var docName = fileName.substring(0,fileName.length -4)

// Set filePath and fileName to source path
filePath = srcDoc.path + '/' + app.activeDocument.name + '.png';

// duplicate image into new document
// =======================================================
var id2784 = charIDToTypeID( "Mk  " );
var desc707 = new ActionDescriptor();
var id2785 = charIDToTypeID( "null" );
var ref508 = new ActionReference();
var id2786 = charIDToTypeID( "Dcmn" );
ref508.putClass( id2786 );
desc707.putReference( id2785, ref508 );
var id2787 = charIDToTypeID( "Nm  " );
desc707.putString( id2787, docName );
var id2788 = charIDToTypeID( "Usng" );
var ref509 = new ActionReference();
var id2789 = charIDToTypeID( "Lyr " );
var id2790 = charIDToTypeID( "Ordn" );
var id2791 = charIDToTypeID( "Trgt" );
ref509.putEnumerated( id2789, id2790, id2791 );
desc707.putReference( id2788, ref509 );
executeAction( id2784, desc707, DialogModes.NO );

// save out the image
var pngFile = new File(filePath);
pngSaveOptions = new PNGSaveOptions();
pngSaveOptions.embedColorProfile = true;
pngSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
pngSaveOptions.matte = MatteType.NONE; pngSaveOptions.quality = 1;

activeDocument.saveAs(pngFile, pngSaveOptions, false, Extension.LOWERCASE);

// close that saved png
app.activeDocument.close()
like image 35
Ghoul Fool Avatar answered Dec 08 '25 07:12

Ghoul Fool



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!