[FIXED] Photoshop CC Javascript – Flip Layer / Image

Issue

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

Solution

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)

Answered By – Sergey Kritskiy

Answer Checked By – Dawn Plyler (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published