扩展脚本。如何将artlayer另存为png

发布于 2025-01-11 01:14:08 字数 327 浏览 0 评论 0原文

如何将 ArtLayer 保存为 png 文件?我可以使用任何 Action API 吗?

var layer = activeDocument.layers[2];
layer.copy();
var myDoc = app.documents.add(2000, 1000, 72, 'export-demo'); 
myDoc.paste();
var type = new PNGSaveOptions();
var fileSpec = new File("e:/ps/" + layer.name + ".png");
myDoc.saveAs(fileSpec, type);

How can i save a ArtLayer as a png file? Are there any Action APIs I can use?

var layer = activeDocument.layers[2];
layer.copy();
var myDoc = app.documents.add(2000, 1000, 72, 'export-demo'); 
myDoc.paste();
var type = new PNGSaveOptions();
var fileSpec = new File("e:/ps/" + layer.name + ".png");
myDoc.saveAs(fileSpec, type);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云朵有点甜 2025-01-18 01:14:08

请注意:我没有代表可以发表评论并询问更多详细信息。所以我想我只会发布我所知道的答案。

有几种方法可以实现这一点。但我发现最简单的方法是关闭所有其他图层的可见性,然后导出 PNG。这看起来像这样:

#target photoshop

var activeDoc = app.activeDocument;
var layers = activeDoc.layers;
var focusLayer = layers[ 2 ];
var visibleLayers = [];

for ( var i = 0; i < layers.length; i++ ) {
    // Add visible layers to array so they can be turned back on after export
    if ( layers[ i ].visible ) visibleLayers.push( layers[ i ] );

    // Turn off visibility of all layers except the focus layer
    if ( layers[ i ] !== focusLayer ) layers[ i ].visible = false;
}

// Export PNG * Change options to your liking
var filepath = "e:/ps/" + layer.name + ".png";
var file = File( filepath );

var exportOptions = new ExportOptionsSaveForWeb();
    exportOptions.format = SaveDocumentType.PNG;
    exportOptions.PNG8 = false; // false = PNG-24
    exportOptions.transparency = true; // true = transparent
    exportOptions.interlaced = false; // true = interlacing on
    exportOptions.includeProfile = false; // false = don't embedd ICC profile

activeDoc.exportDocument(file, ExportType.SAVEFORWEB, exportOptions);

// Turn visible layers back on
for ( var i = 0; i < visibleLayers.length; i++ ) {
    visibleLayers[ i ].visible = true;
}

此方法的缺点是它仅导出到 PSD 的大小,而不会裁剪到图层图像尺寸。

Please note: I don't have the rep to comment and ask for more details. So I figured that I would just post the answer that I know.

There would be a few ways to accomplish this. But the easiest way that I've found to do this is to turn off the visibility of all other layers, then export a PNG. This would look something like this:

#target photoshop

var activeDoc = app.activeDocument;
var layers = activeDoc.layers;
var focusLayer = layers[ 2 ];
var visibleLayers = [];

for ( var i = 0; i < layers.length; i++ ) {
    // Add visible layers to array so they can be turned back on after export
    if ( layers[ i ].visible ) visibleLayers.push( layers[ i ] );

    // Turn off visibility of all layers except the focus layer
    if ( layers[ i ] !== focusLayer ) layers[ i ].visible = false;
}

// Export PNG * Change options to your liking
var filepath = "e:/ps/" + layer.name + ".png";
var file = File( filepath );

var exportOptions = new ExportOptionsSaveForWeb();
    exportOptions.format = SaveDocumentType.PNG;
    exportOptions.PNG8 = false; // false = PNG-24
    exportOptions.transparency = true; // true = transparent
    exportOptions.interlaced = false; // true = interlacing on
    exportOptions.includeProfile = false; // false = don't embedd ICC profile

activeDoc.exportDocument(file, ExportType.SAVEFORWEB, exportOptions);

// Turn visible layers back on
for ( var i = 0; i < visibleLayers.length; i++ ) {
    visibleLayers[ i ].visible = true;
}

The downside to this method is that it only exports to the size of the PSD and does not crop to the layer image dimensions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文