Copy link to clipboard
Copied
hi,
i use the following code to create the brightness/contrast layer
Code:
// Apply auto brightness/contrast adjustment
var autoDescriptor = new ActionDescriptor();
var reference = new ActionReference();
reference.putClass(stringIDToTypeID("adjustmentLayer"));
autoDescriptor.putReference(stringIDToTypeID("null"), reference);
var typeDescriptor = new ActionDescriptor();
var brightnessDescriptor = new ActionDescriptor();
brightnessDescriptor.putBoolean(stringIDToTypeID("auto"), true);
brightnessDescriptor.putBoolean(stringIDToTypeID("useLegacy"), false);
typeDescriptor.putObject(stringIDToTypeID("type"), stringIDToTypeID("brightnessEvent"), brightnessDescriptor);
autoDescriptor.putObject(stringIDToTypeID("using"), stringIDToTypeID("adjustmentLayer"), typeDescriptor);
var resultDesc = executeAction(stringIDToTypeID("make"), autoDescriptor, DialogModes.NO);
///////////////////////
but the contrast value often makes the image too contrasty, i want to set the contrast value = 0,
please give me the command to do it.
2 Correct answers
thank @Ghoul Fool
At the moment, this code runs exactly as i want but unfortunately i dont know how to program in photoshop so this program is the result of patching together parts of code. i think it is not optimized.
Goal:
Apply auto brightness from "auto" Brightness/Contrast function in photoshop but keep only brightness value and remove contrast value.
Step 1:
Run the code to create "auto" brightness/contrast as default (not legacy).
Step 2: Get brightness value and remove layer.
Step 3: Create n
Ok this it a bit of a hack, but it'll do: it will add an auto contrast adjustment layer - set the values and then set contrast to 0 regardless.
auto_brightness();
set_contrast_to_zero();
function auto_brightness()
{
var d = new ActionDescriptor();
var r = new ActionReference();
r.putClass(stringIDToTypeID("adjustmentLayer"));
d.putReference(stringIDToTypeID("null"), r);
var d1 = new ActionDescriptor();
var d2 = new ActionDescriptor();
d2.putBoolean(stringIDToTypeID("
...
Explore related tutorials & articles
Copy link to clipboard
Copied
Comment out the line
brightnessDescriptor.putBoolean(stringIDToTypeID("auto"), true);
Copy link to clipboard
Copied
no, I mean just change the value of contrast = 0, but keep the value of brightness the same.
Copy link to clipboard
Copied
From here you can adjust both the opacity and the contrast.
app.activeDocument.activeLayer.adjustBrightnessContrast(-20, 80);
Copy link to clipboard
Copied
Can I use a command to change the contrast value in the contrast value input field of the Brightness/Contrast control panel?
Copy link to clipboard
Copied
You can add a Brightness and Contrast adjustment layer with this function;
brightness_contrast(50, 0, false);
// function brightnessAndContrast (brightness, contrast)
// --------------------------------------------------------
function brightness_contrast(b, c, legacy)
{
if(legacy == undefined) legacy = false;
// create new Brightness contrast adjustment layer
// =======================================================
var idMk = charIDToTypeID( "Mk " );
var desc834 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref206 = new ActionReference();
var idAdjL = charIDToTypeID( "AdjL" );
ref206.putClass( idAdjL );
desc834.putReference( idnull, ref206 );
var idUsng = charIDToTypeID( "Usng" );
var desc835 = new ActionDescriptor();
var idType = charIDToTypeID( "Type" );
var desc836 = new ActionDescriptor();
var iduseLegacy = stringIDToTypeID( "useLegacy" );
desc836.putBoolean( iduseLegacy, false );
var idBrgC = charIDToTypeID( "BrgC" );
desc835.putObject( idType, idBrgC, desc836 );
var idAdjL = charIDToTypeID( "AdjL" );
desc834.putObject( idUsng, idAdjL, desc835 );
executeAction( idMk, desc834, DialogModes.NO );
// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc826 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref201 = new ActionReference();
var idAdjL = charIDToTypeID( "AdjL" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref201.putEnumerated( idAdjL, idOrdn, idTrgt );
desc826.putReference( idnull, ref201 );
var idT = charIDToTypeID( "T " );
var desc827 = new ActionDescriptor();
var idBrgh = charIDToTypeID( "Brgh" );
desc827.putInteger( idBrgh, b ); //brightness
var idCntr = charIDToTypeID( "Cntr" );
desc827.putInteger( idCntr, c ); //Contrast
var iduseLegacy = stringIDToTypeID( "useLegacy" );
desc827.putBoolean( iduseLegacy, legacy );
var idBrgC = charIDToTypeID( "BrgC" );
desc826.putObject( idT, idBrgC, desc827 );
executeAction( idsetd, desc826, DialogModes.NO );
}
Copy link to clipboard
Copied
thank @Ghoul Fool
At the moment, this code runs exactly as i want but unfortunately i dont know how to program in photoshop so this program is the result of patching together parts of code. i think it is not optimized.
Goal:
Apply auto brightness from "auto" Brightness/Contrast function in photoshop but keep only brightness value and remove contrast value.
Step 1:
Run the code to create "auto" brightness/contrast as default (not legacy).
Step 2: Get brightness value and remove layer.
Step 3: Create new Brightness/Contrast layer with brightness value obtained in step 2 and contrast value set to 0.
Is there any way to set contrast value (set contrast = 0 or 1,2 ..) right after step 1?
CODE:
Copy link to clipboard
Copied
Ok this it a bit of a hack, but it'll do: it will add an auto contrast adjustment layer - set the values and then set contrast to 0 regardless.
auto_brightness();
set_contrast_to_zero();
function auto_brightness()
{
var d = new ActionDescriptor();
var r = new ActionReference();
r.putClass(stringIDToTypeID("adjustmentLayer"));
d.putReference(stringIDToTypeID("null"), r);
var d1 = new ActionDescriptor();
var d2 = new ActionDescriptor();
d2.putBoolean(stringIDToTypeID("auto"), true);
d2.putBoolean(stringIDToTypeID("useLegacy"), false);
d1.putObject(stringIDToTypeID("type"), stringIDToTypeID("brightnessEvent"), d2);
d.putObject(stringIDToTypeID("using"), stringIDToTypeID("adjustmentLayer"), d1);
executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
}
function set_contrast_to_zero()
{
// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc1848 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref354 = new ActionReference();
var idAdjL = charIDToTypeID( "AdjL" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref354.putEnumerated( idAdjL, idOrdn, idTrgt );
desc1848.putReference( idnull, ref354 );
var idT = charIDToTypeID( "T " );
var desc1849 = new ActionDescriptor();
// var idBrgh = charIDToTypeID( "Brgh" );
// desc1849.putInteger( idBrgh, 0 );
var idCntr = charIDToTypeID( "Cntr" );
desc1849.putInteger( idCntr, 0 );
var iduseLegacy = stringIDToTypeID( "useLegacy" );
desc1849.putBoolean( iduseLegacy, false );
var idBrgC = charIDToTypeID( "BrgC" );
desc1848.putObject( idT, idBrgC, desc1849 );
executeAction( idsetd, desc1848, DialogModes.NO );
}
Copy link to clipboard
Copied
thank you,
in the set_contrast function, how to get Brightness value?
Copy link to clipboard
Copied
Sorry, I should have explained in the initial function
brightness_contrast(50, 0, false);
The first parameter is brightness, the second is contrast the third is optional and is legacy mode
Copy link to clipboard
Copied
i mean, i want to get the value of brightness.
i tried getting the value this way but it didn't work
var brightness desc1849.brightness;
var brightness desc1849.Brgh;
it returns undefined
Copy link to clipboard
Copied
Could you please post screenshots with the pertinent Panels (Toolbar, Layers, Properties, Options Bar, …) visible to clarify what the Layer situation is?
Copy link to clipboard
Copied
To get the values of an existing Brightness/Contrast Layer you can try this:
// check brightness/contrast composite settings;
// based on code by michael l hale;
// 2025, use it at your own risk;
if (app.documents.length > 0) {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var layerDesc = executeActionGet(ref);
try {
var aList = layerDesc.getList(stringIDToTypeID("adjustment"));
var bright = aList.getObjectValue(0).getInteger(stringIDToTypeID("brightness"));
var center = aList.getObjectValue(0).getInteger(stringIDToTypeID("center"));
var useLegacy = aList.getObjectValue(0).getBoolean(stringIDToTypeID("useLegacy"));
alert ("brightness/contrast\nbrightness: "+bright+"\ncenter: "+center+"\nlegacy: "+useLegacy
)
} catch (e) {
alert ("either not a brightness/contrast adjustment layer or at unedited default settings")
}
};
Copy link to clipboard
Copied
thank you, it's works.

