Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos Photoshop脚本在保存到png(Mac OS)时忽略透明度_Macos_Png_Transparency_Photoshop - Fatal编程技术网

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

Macos Photoshop脚本在保存到png(Mac OS)时忽略透明度,macos,png,transparency,photoshop,Macos,Png,Transparency,Photoshop,例如,我有一个两层的项目。第一层是透明的。第二层有一个矩形,其不透明度为50% 保存到保存的文件中后,图片看起来像是不透明度为100%(完全不透明)。如何解决这个问题?我使用了以下功能来保存: function SavePNG(saveFile){ var opts = new ExportOptionsSaveForWeb(); opts.format = SaveDocumentType.PNG; opts.PNGB = false; opts.quality

例如,我有一个两层的项目。第一层是透明的。第二层有一个矩形,其不透明度为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,尝试将其添加到选项列表中

opts.transparency = true
好的,尝试导出选项保存

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

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

至少这个解决方案在透明度方面没有问题,并且在不显示对话框的情况下自动工作

当然,第二种方法是有效的,因为我需要手动保存它,因为会出现“保存对话框”。但是,您是否可以在这个对话框中添加至少如何设置文件名?它正确地使用了名称,但是如果它是这个目录中同名的东西,那么它的名称就变成“…copy.png”,这并不优雅,但是我通过复制图像并保存它来解决这个问题。