Photoshop插件-晕影白色-脚本开发-PS插件

发布一下 0 0

PS是一款栅格图像编辑软件,具有许多强大的功能,本文演示如何通过脚本实现晕影白色相关功能,展示从互联网收集而来的一个小插件,供大家学习交流,请勿用于商业用途。

1.插件界面

本文界面是一系列功能的一部分,将逐步展示,但是功能界面是共同的,如下图所示:

https://www.meipian.cn/56fa3cza

2.关键代码

大家可通过源代码阅读,来掌握相关技巧,源代码如下:

if (app) {    try {        MainCatch3();    } catch (e) {    }}function MainCatch3() {    var getName = app.activeDocument.activeLayer.name;    var idslct = charIDToTypeID("slct");    var desc410 = new ActionDescriptor();    var idnull = charIDToTypeID("null");    var ref300 = new ActionReference();    var idLyr = charIDToTypeID("Lyr ");    ref300.putName(idLyr, "White_Vignetting");    desc410.putReference(idnull, ref300);    var idMkVs = charIDToTypeID("MkVs");    desc410.putBoolean(idMkVs, false);    var idLyrI = charIDToTypeID("LyrI");    var list239 = new ActionList();    list239.putInteger(94);    desc410.putList(idLyrI, list239);    executeAction(idslct, desc410, DialogModes.NO);    var idsetd = charIDToTypeID("setd");    var desc422 = new ActionDescriptor();    var idnull = charIDToTypeID("null");    var ref309 = new ActionReference();    var idLyr = charIDToTypeID("Lyr ");    var idOrdn = charIDToTypeID("Ordn");    var idTrgt = charIDToTypeID("Trgt");    ref309.putEnumerated(idLyr, idOrdn, idTrgt);    desc422.putReference(idnull, ref309);    var idT = charIDToTypeID("T   ");    var desc423 = new ActionDescriptor();    var idNm = charIDToTypeID("Nm  ");    desc423.putString(idNm, "White_Vignetting - old");    var idLyr = charIDToTypeID("Lyr ");    desc422.putObject(idT, idLyr, desc423);    executeAction(idsetd, desc422, DialogModes.NO);    var idsetd = charIDToTypeID("setd");    var desc86 = new ActionDescriptor();    var idnull = charIDToTypeID("null");    var ref54 = new ActionReference();    var idLyr = charIDToTypeID("Lyr ");    var idOrdn = charIDToTypeID("Ordn");    var idTrgt = charIDToTypeID("Trgt");    ref54.putEnumerated(idLyr, idOrdn, idTrgt);    desc86.putReference(idnull, ref54);    var idT = charIDToTypeID("T   ");    var desc87 = new ActionDescriptor();    var idClr = charIDToTypeID("Clr ");    var idClr = charIDToTypeID("Clr ");    var idNone = charIDToTypeID("None");    desc87.putEnumerated(idClr, idClr, idNone);    var idLyr = charIDToTypeID("Lyr ");    desc86.putObject(idT, idLyr, desc87);    executeAction(idsetd, desc86, DialogModes.NO);    var idslct = charIDToTypeID("slct");    var desc410 = new ActionDescriptor();    var idnull = charIDToTypeID("null");    var ref300 = new ActionReference();    var idLyr = charIDToTypeID("Lyr ");    ref300.putName(idLyr, getName);    desc410.putReference(idnull, ref300);    var idMkVs = charIDToTypeID("MkVs");    desc410.putBoolean(idMkVs, false);    var idLyrI = charIDToTypeID("LyrI");    var list239 = new ActionList();    list239.putInteger(94);    desc410.putList(idLyrI, list239);    executeAction(idslct, desc410, DialogModes.NO);}function White() {    function step1(enabled, withDialog) {        if (enabled != undefined && !enabled) {            return;        }        var dialogMode = withDialog ? DialogModes.ALL : DialogModes.NO;        var desc1 = new ActionDescriptor();        var ref1 = new ActionReference();        ref1.putClass(PSClass.AdjustmentLayer);        desc1.putReference(PSString.Null, ref1);        var desc2 = new ActionDescriptor();        var desc3 = new ActionDescriptor();        desc3.putEnumerated(PSString.presetKind, PSString.presetKindType, PSString.presetKindDefault);        desc2.putObject(PSKey.Type, PSClass.Curves, desc3);        desc1.putObject(PSKey.Using, PSClass.AdjustmentLayer, desc2);        executeAction(PSEvent.Make, desc1, dialogMode);    }    function step2(enabled, withDialog) {        if (enabled != undefined && !enabled) {            return;        }        var dialogMode = withDialog ? DialogModes.ALL : DialogModes.NO;        executeAction(PSEvent.Invert, undefined, dialogMode);    }    function step3(enabled, withDialog) {        if (enabled != undefined && !enabled) {            return;        }        var dialogMode = withDialog ? DialogModes.ALL : DialogModes.NO;        var desc1 = new ActionDescriptor();        var ref1 = new ActionReference();        ref1.putEnumerated(PSClass.AdjustmentLayer, PSType.Ordinal, PSEnum.Target);        desc1.putReference(PSString.Null, ref1);        var desc2 = new ActionDescriptor();        var list1 = new ActionList();        var desc3 = new ActionDescriptor();        var ref2 = new ActionReference();        ref2.putEnumerated(PSClass.Channel, PSClass.Channel, PSEnum.Composite);        desc3.putReference(PSClass.Channel, ref2);        var list2 = new ActionList();        var desc4 = new ActionDescriptor();        desc4.putDouble(PSKey.Horizontal, 0);        desc4.putDouble(PSKey.Vertical, 0);        list2.putObject(PSClass.Point, desc4);        var desc5 = new ActionDescriptor();        desc5.putDouble(PSKey.Horizontal, 155);        desc5.putDouble(PSKey.Vertical, 106);        list2.putObject(PSClass.Point, desc5);        var desc6 = new ActionDescriptor();        desc6.putDouble(PSKey.Horizontal, 255);        desc6.putDouble(PSKey.Vertical, 255);        list2.putObject(PSClass.Point, desc6);        desc3.putList(PSKey.Curve, list2);        list1.putObject(PSClass.CurvesAdjustment, desc3);        desc2.putList(PSKey.Adjustment, list1);        desc1.putObject(PSKey.To, PSClass.Curves, desc2);        executeAction(PSEvent.Set, desc1, dialogMode);    }    function step4(enabled, withDialog) {        if (enabled != undefined && !enabled) {            return;        }        var dialogMode = withDialog ? DialogModes.ALL : DialogModes.NO;        var desc1 = new ActionDescriptor();        var ref1 = new ActionReference();        ref1.putEnumerated(PSClass.AdjustmentLayer, PSType.Ordinal, PSEnum.Target);        desc1.putReference(PSString.Null, ref1);        var desc2 = new ActionDescriptor();        var list1 = new ActionList();        var desc3 = new ActionDescriptor();        var ref2 = new ActionReference();        ref2.putEnumerated(PSClass.Channel, PSClass.Channel, PSEnum.Composite);        desc3.putReference(PSClass.Channel, ref2);        var list2 = new ActionList();        var desc4 = new ActionDescriptor();        desc4.putDouble(PSKey.Horizontal, 0);        desc4.putDouble(PSKey.Vertical, 0);        list2.putObject(PSClass.Point, desc4);        var desc5 = new ActionDescriptor();        desc5.putDouble(PSKey.Horizontal, 118);        desc5.putDouble(PSKey.Vertical, 149);        list2.putObject(PSClass.Point, desc5);        var desc6 = new ActionDescriptor();        desc6.putDouble(PSKey.Horizontal, 255);        desc6.putDouble(PSKey.Vertical, 255);        list2.putObject(PSClass.Point, desc6);        desc3.putList(PSKey.Curve, list2);        list1.putObject(PSClass.CurvesAdjustment, desc3);        desc2.putList(PSKey.Adjustment, list1);        desc1.putObject(PSKey.To, PSClass.Curves, desc2);        executeAction(PSEvent.Set, desc1, dialogMode);    }    function step5(enabled, withDialog) {        if (enabled != undefined && !enabled) {            return;        }        var dialogMode = withDialog ? DialogModes.ALL : DialogModes.NO;        var desc1 = new ActionDescriptor();        var ref1 = new ActionReference();        ref1.putEnumerated(PSClass.Layer, PSType.Ordinal, PSEnum.Target);        desc1.putReference(PSString.Null, ref1);        var desc2 = new ActionDescriptor();        desc2.putString(PSKey.Name, "Black_Vignetting");        desc1.putObject(PSKey.To, PSClass.Layer, desc2);        executeAction(PSEvent.Set, desc1, dialogMode);    }    function step6(enabled, withDialog) {        if (enabled != undefined && !enabled) {            return;        }        var dialogMode = withDialog ? DialogModes.ALL : DialogModes.NO;        var desc1 = new ActionDescriptor();        var ref1 = new ActionReference();        ref1.putEnumerated(PSClass.Channel, PSClass.Channel, PSClass.Mask);        desc1.putReference(PSString.Null, ref1);        desc1.putBoolean(PSKey.MakeVisible, false);        executeAction(PSEvent.Select, desc1, dialogMode);    }    function step7(enabled, withDialog) {        if (enabled != undefined && !enabled) {            return;        }        var dialogMode = withDialog ? DialogModes.ALL : DialogModes.NO;        var desc1 = new ActionDescriptor();        var ref1 = new ActionReference();        ref1.putEnumerated(PSClass.Layer, PSType.Ordinal, PSEnum.Target);        desc1.putReference(PSString.Null, ref1);        var desc2 = new ActionDescriptor();        desc2.putUnitDouble(sTID("userMaskFeather"), PSUnit.Pixels, 135);        desc1.putObject(PSKey.To, PSClass.Layer, desc2);        executeAction(PSEvent.Set, desc1, dialogMode);    }    function step8(enabled, withDialog) {    }    function step9(enabled, withDialog) {        if (enabled != undefined && !enabled) {            return;        }        var dialogMode = withDialog ? DialogModes.ALL : DialogModes.NO;        var desc1 = new ActionDescriptor();        var ref1 = new ActionReference();        ref1.putEnumerated(PSClass.Layer, PSType.Ordinal, PSEnum.Target);        desc1.putReference(PSString.Null, ref1);        var desc2 = new ActionDescriptor();        desc2.putUnitDouble(PSKey.Opacity, PSUnit.Percent, 60);        desc1.putObject(PSKey.To, PSClass.Layer, desc2);        executeAction(PSEvent.Set, desc1, dialogMode);    }    function step10(enabled, withDialog) {        if (enabled != undefined && !enabled) {            return;        }        var dialogMode = withDialog ? DialogModes.ALL : DialogModes.NO;        var desc1 = new ActionDescriptor();        var ref1 = new ActionReference();        ref1.putEnumerated(PSClass.Layer, PSType.Ordinal, PSEnum.Target);        desc1.putReference(PSString.Null, ref1);        var desc2 = new ActionDescriptor();        desc2.putString(PSKey.Name, "White_Vignetting");        desc1.putObject(PSKey.To, PSClass.Layer, desc2);        executeAction(PSEvent.Set, desc1, dialogMode);    }    function step11(enabled, withDialog) {        if (enabled != undefined && !enabled) {            return;        }        var dialogMode = withDialog ? DialogModes.ALL : DialogModes.NO;        var desc1 = new ActionDescriptor();        var ref1 = new ActionReference();        ref1.putEnumerated(PSClass.Layer, PSType.Ordinal, PSEnum.Target);        desc1.putReference(PSString.Null, ref1);        var desc2 = new ActionDescriptor();        desc2.putEnumerated(PSKey.Color, PSKey.Color, PSEnum.Blue);        desc1.putObject(PSKey.To, PSClass.Layer, desc2);        executeAction(PSEvent.Set, desc1, dialogMode);    }    function step12(enabled, withDialog) {        if (enabled != undefined && !enabled) {            return;        }        var dialogMode = withDialog ? DialogModes.ALL : DialogModes.NO;        var desc1 = new ActionDescriptor();        var ref1 = new ActionReference();        ref1.putEnumerated(PSClass.Layer, PSType.Ordinal, PSEnum.Target);        desc1.putReference(PSString.Null, ref1);        var desc2 = new ActionDescriptor();        desc2.putEnumerated(PSKey.Mode, PSType.BlendMode, PSEnum.Luminosity);        desc1.putObject(PSKey.To, PSClass.Layer, desc2);        executeAction(PSEvent.Set, desc1, dialogMode);    }    step1();    step2();    step3();    step4();    step5();    step6();    step7();    step8();    step9();    step10();    step11();    step12();}cTID = function(s) {    return app.charIDToTypeID(s);};sTID = function(s) {    return app.stringIDToTypeID(s);};White.loadSymbols = function() {    var dbgLevel = $.level;    $.level = 0;    try {        PSConstants;        return;    } catch (e) {    } finally {        $.level = dbgLevel;    }    var needDefs = true;    $.level = 0;    try {        PSClass;        needDefs = false;    } catch (e) {    } finally {        $.level = dbgLevel;    }    if (needDefs) {        PSClass = function() {        };        PSEnum = function() {        };        PSEvent = function() {        };        PSForm = function() {        };        PSKey = function() {        };        PSType = function() {        };        PSUnit = function() {        };        PSString = function() {        };    }    PSClass.AdjustmentLayer = cTID("AdjL");    PSClass.Channel = cTID("Chnl");    PSClass.Curves = cTID("Crvs");    PSClass.CurvesAdjustment = cTID("CrvA");    PSClass.Layer = cTID("Lyr ");    PSClass.Mask = cTID("Msk ");    PSClass.Point = cTID("Pnt ");    PSEnum.Blue = cTID("Bl  ");    PSEnum.Composite = cTID("Cmps");    PSEnum.Luminosity = cTID("Lmns");    PSEnum.Target = cTID("Trgt");    PSEvent.Invert = cTID("Invr");    PSEvent.Make = cTID("Mk  ");    PSEvent.Select = cTID("slct");    PSEvent.Set = cTID("setd");    PSKey.Adjustment = cTID("Adjs");    PSKey.Color = cTID("Clr ");    PSKey.Curve = cTID("Crv ");    PSKey.Horizontal = cTID("Hrzn");    PSKey.MakeVisible = cTID("MkVs");    PSKey.Mode = cTID("Md  ");    PSKey.Name = cTID("Nm  ");    PSKey.Opacity = cTID("Opct");    PSKey.To = cTID("T   ");    PSKey.Type = cTID("Type");    PSKey.Using = cTID("Usng");    PSKey.Vertical = cTID("Vrtc");    PSString.Null = sTID("null");    PSString.addToSelectionContinuous = sTID("addToSelectionContinuous");    PSString.presetKind = sTID("presetKind");    PSString.presetKindDefault = sTID("presetKindDefault");    PSString.presetKindType = sTID("presetKindType");    PSString.selectionModifier = sTID("selectionModifier");    PSString.selectionModifierType = sTID("selectionModifierType");    PSType.BlendMode = cTID("BlnM");    PSType.Ordinal = cTID("Ordn");    PSUnit.Percent = cTID("#Prc");    PSUnit.Pixels = cTID("#Pxl");};White.loadSymbols();White.main = function() {    White();};White.main();

3.代码转执行

  使用记事本或者notepad++等文本编辑器,将代码拷贝至文本文件,然后修改后缀名为js或者jsx,最后再PS软件菜单文件》脚本》浏览,点执行即可,也可以将脚本放在预设文件夹内,会显示再脚本下的二级子菜单。如下图所示:

https://www.meipian.cn/56fa3cza

PS脚本执行.png

4.作者答疑


文章引用至 作者联系方式

文章引用至 插件开发流程 - 知乎

版权声明:内容来源于互联网和用户投稿 如有侵权请联系删除

本文地址:http://0561fc.cn/82462.html