保存到png时,Photoshop脚本忽略透明度(Mac OS)

时间:2013-05-31 14:37:16

标签: macos png transparency photoshop

例如,我有一个有两层的项目。第一层是透明的。第二层有一个矩形,它的不透明度是50%。

保存在保存的文件中后,图片看起来像不透明度为100%(完全不透明)。怎么解决这个?我使用以下功能保存:

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

我用过photoshop cs6

2 个答案:

答案 0 :(得分:3)

我在photoshop论坛找到了解决方案:

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

至少此解决方案没有透明度问题,并且无需显示对话框即可自动运行

答案 1 :(得分:2)

尝试将此添加到选项列表

opts.transparency = true

好的,试试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);
}

我通常会沿着这些方向使用某些东西:

// 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()