简体   繁体   中英

Photoshop CC Javascript - Flip Layer / Image

I need to be able to flip an image / active layer either vertically or horizontally.

Looking throughout the Adobe Photoshop CC Javascript Reference there doesn't appear to be a flip method for the activelayer/object.

doc.flipCanvas(Direction.VERTICAL)

Does work but that obviously flips the entire document vertically where as I want to do it on just the active layer

I can see in the invert() method it does mention:

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

And that says the following:

rotate (angle [, anchor]) -

Rotates the selection by the specified amount around the specified anchor

I'm already using the rotate method like so elsewhere and cannot see how I can flip the image through this?

obj.rotate( rotation,  AnchorPosition.TOPLEFT );

There's no flip method for ArtLayer, you can use .resize instead:

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

(there's also a third argument for an anchor point)

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

Will flip a layer horizontally.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM