Photoshop CC Javascript - 翻转图层/图像

Photoshop CC Javascript - Flip Layer / Image

我需要能够垂直或水平翻转图像/活动层。

纵观 Adobe Photoshop CC Javascript Reference,activelayer/object 似乎没有翻转方法。

doc.flipCanvas(Direction.VERTICAL)

确实有效,但显然会垂直翻转整个文档,因为我只想在活动层上这样做

我可以在 invert() 方法中看到它确实提到了:

inverts the selection (deselects the selection and selects the rest of the layer or document). Tip. To flip the selection shape, see rotate

上面写着:

rotate (angle [, anchor]) -

Rotates the selection by the specified amount around the specified anchor

我已经像其他地方一样使用旋转方法,但看不出如何通过它翻转图像?

obj.rotate( rotation,  AnchorPosition.TOPLEFT );

ArtLayer没有翻转方法,可以用.resize代替:

Resizes the layer to the specified dimensions (as a percentage of its current size) and places it in the specified position.

activeDocument.activeLayer.resize(-100,undefined); //will flip layer horizontally
activeDocument.activeLayer.resize(undefined,-100); //will flip layer vertically

(锚点还有第三个参数)

var idFlip = charIDToTypeID( "Flip" );
var desc16024 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2273 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref2273.putEnumerated( idLyr, idOrdn, idTrgt );
desc16024.putReference( idnull, ref2273 );
var idAxis = charIDToTypeID( "Axis" );
var idOrnt = charIDToTypeID( "Ornt" );
var idHrzn = charIDToTypeID( "Hrzn" );
desc16024.putEnumerated( idAxis, idOrnt, idHrzn );
executeAction( idFlip, desc16024, DialogModes.NO );

将水平翻转一层。