Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
189 views
in Technique[技术] by (71.8m points)

javascript - Modify Gradient Overlay Position

I am trying to export a layer multiple times, however, with different Gradient Overlay Y values. Seen here

The documentation for Photoshop scripting is really bad, so I've only manage to create a Color Overlay (which, unfortunately, modifies all layers):

applyColorOverlay(
{
    r: 255,
    g: 0,
    b: 0,
})

function applyColorOverlay(color)
{
    var desc6 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putProperty(charIDToTypeID('Prpr'), charIDToTypeID('Lefx'));
    ref1.putEnumerated(charIDToTypeID('Lyr'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
    desc6.putReference(charIDToTypeID('null'), ref1);
    var desc7 = new ActionDescriptor();
    var desc8 = new ActionDescriptor();
    desc8.putBoolean(charIDToTypeID('enab'), true);
    desc8.putBoolean(stringIDToTypeID('present'), true);
    desc8.putBoolean(stringIDToTypeID('showInDialog'), true);
    desc8.putEnumerated(charIDToTypeID('Md'), charIDToTypeID('BlnM'), charIDToTypeID('Nrml'));
    var desc9 = new ActionDescriptor();
    desc9.putDouble(charIDToTypeID('Rd'), color.r);
    desc9.putDouble(charIDToTypeID('Grn'), color.g);
    desc9.putDouble(charIDToTypeID('Bl'), color.b);
    desc8.putObject(charIDToTypeID('Clr'), charIDToTypeID('RGBC'), desc9);
    desc8.putUnitDouble(charIDToTypeID('Opct'), charIDToTypeID('#Prc'), 100.000000);
    desc7.putObject(charIDToTypeID('SoFi'), charIDToTypeID('SoFi'), desc8);
    desc6.putObject(charIDToTypeID('T'), charIDToTypeID('Lefx'), desc7);
    executeAction(charIDToTypeID('setd'), desc6, DialogModes.NO);
};

So, would it be possible to modify the Gradient Overlay Y value of a specific layer?

Note: I am using Photopea, and scripting is identical to Photoshop (since the example above worked).

question from:https://stackoverflow.com/questions/65906283/modify-gradient-overlay-position

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This should work. it's not pretty though :D. - It's just script listener code with a vertical and horizontal offset applied to the function.

I hope that's what you're after. Ironically your Photopea code doesn't work with my version of Photoshop (19.16)

applyColorOverlay(
{
    r: 255,
    g: 0,
    b: 0,

}, 10, 0);

function applyColorOverlay(color, v, h)
{

    // =======================================================
    var idsetd = charIDToTypeID( "setd" );
    var desc28 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
    var ref9 = new ActionReference();
    var idPrpr = charIDToTypeID( "Prpr" );
    var idLefx = charIDToTypeID( "Lefx" );
    ref9.putProperty( idPrpr, idLefx );
    var idLyr = charIDToTypeID( "Lyr " );
    var idOrdn = charIDToTypeID( "Ordn" );
    var idTrgt = charIDToTypeID( "Trgt" );
    ref9.putEnumerated( idLyr, idOrdn, idTrgt );
    desc28.putReference( idnull, ref9 );
    var idT = charIDToTypeID( "T   " );
    var desc29 = new ActionDescriptor();
    var idScl = charIDToTypeID( "Scl " );
    var idPrc = charIDToTypeID( "#Prc" );
    desc29.putUnitDouble( idScl, idPrc, 416.666667 );
    var idGrFl = charIDToTypeID( "GrFl" );
    var desc30 = new ActionDescriptor();
    var idenab = charIDToTypeID( "enab" );
    desc30.putBoolean( idenab, true );
    var idpresent = stringIDToTypeID( "present" );
    desc30.putBoolean( idpresent, true );
    var idshowInDialog = stringIDToTypeID( "showInDialog" );
    desc30.putBoolean( idshowInDialog, true );
    var idMd = charIDToTypeID( "Md  " );
    var idBlnM = charIDToTypeID( "BlnM" );
    var idNrml = charIDToTypeID( "Nrml" );
    desc30.putEnumerated( idMd, idBlnM, idNrml );
    var idOpct = charIDToTypeID( "Opct" );
    var idPrc = charIDToTypeID( "#Prc" );
    desc30.putUnitDouble( idOpct, idPrc, 100.000000 );
    var idGrad = charIDToTypeID( "Grad" );
    var desc31 = new ActionDescriptor();
    var idNm = charIDToTypeID( "Nm  " );
    desc31.putString( idNm, """$$$/DefaultGradient/ForegroundToBackground=Foreground to Background""" );
    var idGrdF = charIDToTypeID( "GrdF" );
    var idGrdF = charIDToTypeID( "GrdF" );
    var idCstS = charIDToTypeID( "CstS" );
    desc31.putEnumerated( idGrdF, idGrdF, idCstS );
    var idIntr = charIDToTypeID( "Intr" );
    desc31.putDouble( idIntr, 4096.000000 );
    var idClrs = charIDToTypeID( "Clrs" );
    var list2 = new ActionList();
    var desc32 = new ActionDescriptor();
    var idClr = charIDToTypeID( "Clr " );
    var desc33 = new ActionDescriptor();
    var idRd = charIDToTypeID( "Rd  " );
    desc33.putDouble( idRd, color.r ); //R
    var idGrn = charIDToTypeID( "Grn " );
    desc33.putDouble( idGrn, color.g ); //g
    var idBl = charIDToTypeID( "Bl  " );
    desc33.putDouble( idBl, color.b );
    var idRGBC = charIDToTypeID( "RGBC" );
    desc32.putObject( idClr, idRGBC, desc33 );
    var idType = charIDToTypeID( "Type" );
    var idClry = charIDToTypeID( "Clry" );
    var idUsrS = charIDToTypeID( "UsrS" );
    desc32.putEnumerated( idType, idClry, idUsrS );
    var idLctn = charIDToTypeID( "Lctn" );
    desc32.putInteger( idLctn, 0 );
    var idMdpn = charIDToTypeID( "Mdpn" );
    desc32.putInteger( idMdpn, 50 );
    var idClrt = charIDToTypeID( "Clrt" );
    list2.putObject( idClrt, desc32 );
    var desc34 = new ActionDescriptor();
    var idClr = charIDToTypeID( "Clr " );
    var desc35 = new ActionDescriptor();
    var idRd = charIDToTypeID( "Rd  " );
    desc35.putDouble( idRd, 255.000000 );
    var idGrn = charIDToTypeID( "Grn " );
    desc35.putDouble( idGrn, 255.000000 );
    var idBl = charIDToTypeID( "Bl  " );
    desc35.putDouble( idBl, 255.000000 );
    var idRGBC = charIDToTypeID( "RGBC" );
    desc34.putObject( idClr, idRGBC, desc35 );
    var idType = charIDToTypeID( "Type" );
    var idClry = charIDToTypeID( "Clry" );
    var idUsrS = charIDToTypeID( "UsrS" );
    desc34.putEnumerated( idType, idClry, idUsrS );
    var idLctn = charIDToTypeID( "Lctn" );
    desc34.putInteger( idLctn, 4096 );
    var idMdpn = charIDToTypeID( "Mdpn" );
    desc34.putInteger( idMdpn, 50 );
    var idClrt = charIDToTypeID( "Clrt" );
    list2.putObject( idClrt, desc34 );
    desc31.putList( idClrs, list2 );
    var idTrns = charIDToTypeID( "Trns" );
    var list3 = new ActionList();
    var desc36 = new ActionDescriptor();
    var idOpct = charIDToTypeID( "Opct" );
    var idPrc = charIDToTypeID( "#Prc" );
    desc36.putUnitDouble( idOpct, idPrc, 100.000000 );
    var idLctn = charIDToTypeID( "Lctn" );
    desc36.putInteger( idLctn, 0 );
    var idMdpn = charIDToTypeID( "Mdpn" );
    desc36.putInteger( idMdpn, 50 );
    var idTrnS = charIDToTypeID( "TrnS" );
    list3.putObject( idTrnS, desc36 );
    var desc37 = new ActionDescriptor();
    var idOpct = charIDToTypeID( "Opct" );
    var idPrc = charIDToTypeID( "#Prc" );
    desc37.putUnitDouble( idOpct, idPrc, 100.000000 );
    var idLctn = charIDToTypeID( "Lctn" );
    desc37.putInteger( idLctn, 4096 );
    var idMdpn = charIDToTypeID( "Mdpn" );
    desc37.putInteger( idMdpn, 50 );
    var idTrnS = charIDToTypeID( "TrnS" );
    list3.putObject( idTrnS, desc37 );
    desc31.putList( idTrns, list3 );
    var idGrdn = charIDToTypeID( "Grdn" );
    desc30.putObject( idGrad, idGrdn, desc31 );
    var idAngl = charIDToTypeID( "Angl" );
    var idAng = charIDToTypeID( "#Ang" );
    desc30.putUnitDouble( idAngl, idAng, 90.000000 );
    var idType = charIDToTypeID( "Type" );
    var idGrdT = charIDToTypeID( "GrdT" );
    var idLnr = charIDToTypeID( "Lnr " );
    desc30.putEnumerated( idType, idGrdT, idLnr );
    var idRvrs = charIDToTypeID( "Rvrs" );
    desc30.putBoolean( idRvrs, false );
    var idDthr = charIDToTypeID( "Dthr" );
    desc30.putBoolean( idDthr, false );
    var idAlgn = charIDToTypeID( "Algn" );
    desc30.putBoolean( idAlgn, true );
    var idScl = charIDToTypeID( "Scl " );
    var idPrc = charIDToTypeID( "#Prc" );
    desc30.putUnitDouble( idScl, idPrc, 100.000000 );
    var idOfst = charIDToTypeID( "Ofst" );
    var desc38 = new ActionDescriptor();
    var idHrzn = charIDToTypeID( "Hrzn" );
    var idPrc = charIDToTypeID( "#Prc" );
    desc38.putUnitDouble( idHrzn, idPrc, h );
    var idVrtc = charIDToTypeID( "Vrtc" );
    var idPrc = charIDToTypeID( "#Prc" );
    desc38.putUnitDouble( idVrtc, idPrc, v );
    var idPnt = charIDToTypeID( "Pnt " );
    desc30.putObject( idOfst, idPnt, desc38 );
    var idGrFl = charIDToTypeID( "GrFl" );
    desc29.putObject( idGrFl, idGrFl, desc30 );
    var idLefx = charIDToTypeID( "Lefx" );
    desc28.putObject( idT, idLefx, desc29 );
    executeAction( idsetd, desc28, DialogModes.NO );

};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...