Skip to main content
Participant
April 17, 2016
Answered

Flip and invert colors of selected area - Javascript for Photoshop

  • April 17, 2016
  • 1 reply
  • 3460 views

So I am writing a script for Photoshop using Javascript and I have a selection that I want to flip vertically and then invert the colors of a layer, however I can't seem to find a command on how to do this.

Here's what I've tried:

docRef.selection.select(shapeRef)

docRef.activeArtLayer.Invert()

docRef.activeArtLayer.flip(Direction.VERTICAL)

This topic has been closed for replies.
Correct answer Chuck Uebele

I haven't checked your other lines, but your invert line should be:

docRef.activeLayer.invert()

1 reply

Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
April 17, 2016

I haven't checked your other lines, but your invert line should be:

docRef.activeLayer.invert()

Participant
April 17, 2016

Thank You

pixxxelschubser
Community Expert
Community Expert
April 17, 2016

This answers Chuck Uebele​ before

var docRef = app.activeDocument;

docRef.activeLayer.invert();

This will flip the active layer (a code IMHO written by Paul Riggott)

FlipLayer('Vrtc');

function FlipLayer(direction) {

// direction = "Vrtc" or "Hrzn"

function cTID(s) { return app.charIDToTypeID(s) };

function sTID(s) { return app.stringIDToTypeID(s) };

var desc01 = new ActionDescriptor();

var ref01 = new ActionReference(); ref01.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt') );

    desc01.putReference(cTID('null'), ref01);

    desc01.putEnumerated(cTID('Axis'), cTID('Ornt'), cTID(direction));

executeAction(cTID('Flip'), desc01, DialogModes.NO);

}

And this will set your (rectangle) selection (the values are hardcoded)

var shapeRef = [[0, 0], [0, 150], [200, 150], [200, 0]];

docRef.selection.select (shapeRef);

Have fun