我需要创建一个Photoshop脚本(我正在使用Java脚本),它会拍摄一些图像并对所有图像应用相同的蒙版。
(Here is what I mean by applying a mask)
使用此代码加载图像后
var sourceImageDoc = app.open(new File("./image.png"))
var maskImageDoc = app.open(new File("./mask.png"))
如何设置 maskImageDoc 作为 sourceImageDoc 的掩码?
答案 0 :(得分:0)
以下是我的一个适用于CS3 +的脚本的一些片段。正如您所看到的,它使用丑陋的脚本侦听器代码 - 如果您将其应用于图层而不是组,您可能需要调整该部分?我不确定我是否记得曾经在图层而不是图层集上使用该功能。
//mask group to paper area
app.activeDocument.activeLayer = lyr;
selectRasterLayerContents();
app.activeDocument.activeLayer = grp;
AddMaskToGroup();
//Selects the contents of the active layer.
function selectRasterLayerContents() {
var id47 = charIDToTypeID( "setd" );
var desc11 = new ActionDescriptor();
var id48 = charIDToTypeID( "null" );
var ref11 = new ActionReference();
var id49 = charIDToTypeID( "Chnl" );
var id50 = charIDToTypeID( "fsel" );
ref11.putProperty( id49, id50 );
desc11.putReference( id48, ref11 );
var id51 = charIDToTypeID( "T " );
var ref12 = new ActionReference();
var id52 = charIDToTypeID( "Chnl" );
var id53 = charIDToTypeID( "Chnl" );
var id54 = charIDToTypeID( "Trsp" );
ref12.putEnumerated( id52, id53, id54 );
desc11.putReference( id51, ref12 );
executeAction( id47, desc11, DialogModes.NO );
}
//adds a mask revealing the selection to the active group
function AddMaskToGroup() {
var id42 = charIDToTypeID( "Mk " );
var desc8 = new ActionDescriptor();
var id43 = charIDToTypeID( "Nw " );
var id44 = charIDToTypeID( "Chnl" );
desc8.putClass( id43, id44 );
var id45 = charIDToTypeID( "At " );
var ref10 = new ActionReference();
var id46 = charIDToTypeID( "Chnl" );
var id47 = charIDToTypeID( "Chnl" );
var id48 = charIDToTypeID( "Msk " );
ref10.putEnumerated( id46, id47, id48 );
desc8.putReference( id45, ref10 );
var id49 = charIDToTypeID( "Usng" );
var id50 = charIDToTypeID( "UsrM" );
var id51 = charIDToTypeID( "RvlS" );
desc8.putEnumerated( id49, id50, id51 );
executeAction( id42, desc8, DialogModes.NO );
}
答案 1 :(得分:0)
应用图层蒙版很痛苦,因为脚本侦听器不会直接听到它。
你会想要这个
function applyLayerMask()
{
var id1949 = charIDToTypeID( "Dlt " );
var desc398 = new ActionDescriptor();
var id1950 = charIDToTypeID( "null" );
var ref291 = new ActionReference();
var id1951 = charIDToTypeID( "Chnl" );
var id1952 = charIDToTypeID( "Chnl" );
var id1953 = charIDToTypeID( "Msk " );
ref291.putEnumerated( id1951, id1952, id1953 );
desc398.putReference( id1950, ref291 );
var id1954 = charIDToTypeID( "Aply" );
desc398.putBoolean( id1954, true );
executeAction( id1949, desc398, DialogModes.NO );
}
答案 2 :(得分:0)
这是我的代码,用于将图层蒙版应用到当前选定的对象(前提是它有一个选择)。
const layerMask = function () {
const makeID = stringIDToTypeID('make')
const newID = stringIDToTypeID('new')
const channelID = stringIDToTypeID('channel')
const atID = stringIDToTypeID('at')
const usingID = stringIDToTypeID('using')
const userMaskEnabledID = stringIDToTypeID('userMaskEnabled')
const revealSelectionID = stringIDToTypeID('revealSelection')
const actionDesc = new ActionDescriptor()
const actionRef = new ActionReference()
actionDesc.putClass(newID, channelID)
actionRef.putEnumerated(channelID, channelID, maskID)
actionDesc.putReference(atID, actionRef)
actionDesc.putEnumerated(usingID, userMaskEnabledID, revealSelectionID)
executeAction(makeID, actionDesc, DialogModes.NO)
}
在 Photoshop CC 2021 中测试