Skip to main content
KOSUTE
New Participant
July 25, 2014
Answered

How to add an art layer posterize levels 50 with javascript?

  • July 25, 2014
  • 1 reply
  • 724 views

Hello,

I need a javascript to create a new art layer posterize in order to reduce the weight of my png.

But my javascript command does'nt work:

var LayerISO = app.activeDocument.artLayers.posterize.add(50);

Can someone help me?

Thanks.

This topic has been closed for replies.
Correct answer Muppet Mark

You can do 2 ways… Using the DOM or scriptlistener…

#target photoshop

var doc = app.activeDocument.artLayers[0].posterize( 50 );

//posterizeLayer( 50 );

function posterizeLayer( numb ) {

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

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

    var desc66 = new ActionDescriptor();

    desc66.putInteger( cTID( 'Lvls' ), numb );

    executeAction( cTID( 'Pstr' ), desc66, DialogModes.NO );

};

artLayers is an Array so target the one you want by index… No need for the .add()

1 reply

Muppet MarkCorrect answer
Inspiring
July 25, 2014

You can do 2 ways… Using the DOM or scriptlistener…

#target photoshop

var doc = app.activeDocument.artLayers[0].posterize( 50 );

//posterizeLayer( 50 );

function posterizeLayer( numb ) {

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

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

    var desc66 = new ActionDescriptor();

    desc66.putInteger( cTID( 'Lvls' ), numb );

    executeAction( cTID( 'Pstr' ), desc66, DialogModes.NO );

};

artLayers is an Array so target the one you want by index… No need for the .add()

KOSUTE
KOSUTEAuthor
New Participant
July 25, 2014

You awesome Muppet MarK!

Thank you !

Inspiring
July 25, 2014

And ur mad it's a one liner...! (DOM)

You were close but no cigar...!

Sent from my iPhone