Skip to main content
Participating Frequently
September 8, 2021
Question

Javascript Shadows/Highlights

  • September 8, 2021
  • 2 replies
  • 747 views

Hi,

I would like to add to my layer stack a Shadows/Highlights layer using javascript. Could someone provide me a example?

Thank you,

-JPK

This topic has been closed for replies.

2 replies

Stephen Marsh
Community Expert
Community Expert
September 8, 2021

@jpkoc – Are you perhaps referring to the Image > Adjustments > Shadows/Highlights command?

 

If so, it is not available as an adjustment layer, so to use this command it would need to be applied to a smart object or a new layer containing a merged copy of the current document layers, stacked at the top.

 

The actual Shadows/Highlights command is not available in the DOM code, one must use the ScriptListener plug-in to record the raw action managewr code. It can be run with fixed values without a dialog, or for interactive use the dialog can be presented.

 

EDIT: I'll post the code for future reference, even if this is not what you are looking for now, it may help somebody else in the future! Here it is in a function from the Clean SL script:

 

 

adaptCorrect(35, 50, 30, 0, 50, 30, 0.01, 0.01, 0, 20);

function adaptCorrect(amount, width, radius, amount2, width2, radius2, blackClip, whiteClip, center, colorCorrection) {
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var descriptor = new ActionDescriptor();
    var descriptor2 = new ActionDescriptor();
    var descriptor3 = new ActionDescriptor();
    descriptor2.putUnitDouble(s2t("amount"), s2t("percentUnit"), amount);
    descriptor2.putUnitDouble(s2t("width"), s2t("percentUnit"), width);
    descriptor2.putInteger(s2t("radius"), radius);
    descriptor.putObject(s2t("shadowMode"), s2t("adaptCorrectTones"), descriptor2);
    descriptor3.putUnitDouble(s2t("amount"), s2t("percentUnit"), amount2);
    descriptor3.putUnitDouble(s2t("width"), s2t("percentUnit"), width2);
    descriptor3.putInteger(s2t("radius"), radius2);
    descriptor.putObject(s2t("highlightMode"), s2t("adaptCorrectTones"), descriptor3);
    descriptor.putDouble(s2t("blackClip"), blackClip);
    descriptor.putDouble(s2t("whiteClip"), whiteClip);
    descriptor.putInteger(s2t("center"), center);
    descriptor.putInteger(s2t("colorCorrection"), colorCorrection);
    // DialogModes.NO | DialogModes.ALL
    executeAction(s2t("adaptCorrect"), descriptor, DialogModes.NO);
}

 

 

JJMack
Community Expert
Community Expert
September 9, 2021

Stephen lets say the script adds a stamp visible layers layer to the top of the layer stack then  uses the image Adjustment Shadows and Highlights feature,  How would the script know what adjustment settings values would be suitable for the layers current content? I believe in a Script or Action the Shadow and  Highlight Adjustment would  need to be made interactive so the user can make an adjustment the is acceptable to their taste for the current content. Your Action manager code shows the adjustment has 10 settings. What setting would be appropriate for all possible content.

JJMack
Stephen Marsh
Community Expert
Community Expert
September 9, 2021

As you are aware, it would depend on the workflow and image content.

 

Adobe offer some default values, whether or not they are useful or not. They could have just as easily made the various parameters zero:

 

 

For a script manually adjusting an image by image, either manually or via an interactive batch, one may use different values per image in interactive mode by setting the script to use DialogModes.ALL

 

For other workflows, this may be required as a fully automated adjustment. The values may come from testing beforehand over a sampling of images, the value of unattended automation may outway the benefit of working each image one by one. For some other workflows a set of fixed values that achieve a specific result may be used and the script would use DialogModes.NO

 

It all depends, there are no magic answers.

 

 

JJMack
Community Expert
Community Expert
September 8, 2021

How are you going to create the content for the layer and how is it going to be blended into the layers stack. It easy to add a layer in javasctipt and name the layer "Shadows/Highlights"  Creating shadows and highlights for a stack of layers is a different matter.

 

layer = doc.artLayers.add();        // Add a Layer
layer.name = " Shadows/Highlights"; // Name Layer

 

JJMack