开发者

Adding a vector mask to a layer?

i'd like to know how to add a vector mask in photoshop to a given layer with photoshop sript (.jsx)?

I m not 100% sure what i want is called "vector mask" in photoshop. I've got a picture and a mask in black and white, i'd like to automaticly add the mask to the image so we can only see what is under the white region. Under the black region must be transparent pixel. this must be simple but i can't find anything on the online doc...

here is what i did so far...

        var f_image = File(imageAdress)
    open(f_image)

    var bgLayer = activeDocument.artLayers[0]
    bgLayer.isBackgroundLayer = false;


     var maskLayer = activeDocument.artLayers.add()
     maskLayer.name = "mask"

    open(File(maskAdress))
    // flatten the document so we get everything and then copy
    app.activeDocument.flatten()
    app.activeDocument.selection.selectAll()
    app.activeDocument.selection.开发者_JAVA技巧copy()
    // don’t save anything we did
    app.activeDocument.close(SaveOptions.DONOTSAVECHANGES)
    app.activeDocument.paste()

// how to set the mask as a mask????

Thanks !


You don't want vector mask; you want layer masks. Here's a function that I normally use. It'll put a layer mask on a layer with a selection. It won't work on a empty layer, however

makeMask()

// FUNCTION MAKE MASK
function makeMask()
{
  var id4556 = charIDToTypeID( "setd" );
  var desc983 = new ActionDescriptor();
  var id4557 = charIDToTypeID( "null" );
  var ref657 = new ActionReference();
  var id4558 = charIDToTypeID( "Chnl" );
  var id4559 = charIDToTypeID( "fsel" );
  ref657.putProperty( id4558, id4559 );
  desc983.putReference( id4557, ref657 );
  var id4560 = charIDToTypeID( "T   " );
  var ref658 = new ActionReference();
  var id4561 = charIDToTypeID( "Chnl" );
  var id4562 = charIDToTypeID( "Chnl" );
  var id4563 = charIDToTypeID( "Trsp" );
  ref658.putEnumerated( id4561, id4562, id4563 );
  desc983.putReference( id4560, ref658 );
  executeAction( id4556, desc983, DialogModes.NO );

  var id4564 = charIDToTypeID( "Mk  " );
  var desc984 = new ActionDescriptor();
  var id4565 = charIDToTypeID( "Nw  " );
  var id4566 = charIDToTypeID( "Chnl" );
  desc984.putClass( id4565, id4566 );
  var id4567 = charIDToTypeID( "At  " );
  var ref659 = new ActionReference();
  var id4568 = charIDToTypeID( "Chnl" );
  var id4569 = charIDToTypeID( "Chnl" );
  var id4570 = charIDToTypeID( "Msk " );
  ref659.putEnumerated( id4568, id4569, id4570 );
  desc984.putReference( id4567, ref659 );
  var id4571 = charIDToTypeID( "Usng" );
  var id4572 = charIDToTypeID( "UsrM" );
  var id4573 = charIDToTypeID( "RvlS" );
  desc984.putEnumerated( id4571, id4572, id4573 );
  executeAction( id4564, desc984, DialogModes.NO );
}


I'm not sure how to make this via script, but to add a vector mask to a layer you have to:

  1. Draw a vector path (appears in the Paths window)
  2. Have the path active (selected)
  3. Go to the Layer menu, Vector Mask, Current Path
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜