1

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 );
1
  • Interesting question! I don't see a way to transform a flip. I hope someone else has a better answer for you.
    – TimHayes
    Nov 20, 2018 at 16:42

2 Answers 2

3

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)

0
0
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.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.