PS是一款栅格图像编辑软件,模块众多。提供了脚本,动态连接库等多种扩展机制,本文演示如何通过脚本实现修复高光相关功能,展示从互联网收集而来的一个小插件,供大家学习交流,请勿用于商业用途。

1.插件界面

  本文界面是一系列功能的一部分,将逐步展示,但是功能界面是共同的,如下图所示:
在这里插入图片描述

2.关键代码-修复高光

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

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

$._ext_002 = {
    run: function MattifierPowder() {
        // Make
        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(sTID("contentLayer"));
            desc1.putReference(cTID('null'), ref1);
            var desc2 = new ActionDescriptor();
            var desc3 = new ActionDescriptor();
            var desc4 = new ActionDescriptor();
            desc4.putDouble(cTID('Rd  '), 221.000518798828);
            desc4.putDouble(cTID('Grn '), 161.001434326172);
            desc4.putDouble(cTID('Bl  '), 129.001922607422);
            desc3.putObject(cTID('Clr '), sTID("RGBColor"), desc4);
            desc2.putObject(cTID('Type'), sTID("solidColorLayer"), desc3);
            desc1.putObject(cTID('Usng'), sTID("contentLayer"), desc2);
            executeAction(cTID('Mk  '), desc1, dialogMode);
        };

        // Set
        function step2(enabled, withDialog) {
            if (enabled != undefined && !enabled)
                return;
            var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
            var desc1 = new ActionDescriptor();
            var ref1 = new ActionReference();
            ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
            desc1.putReference(cTID('null'), ref1);
            var desc2 = new ActionDescriptor();
            desc2.putString(cTID('Nm  '), "Skin Color");
            desc1.putObject(cTID('T   '), cTID('Lyr '), desc2);
            executeAction(cTID('setd'), desc1, dialogMode);
        };

        // Set
        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(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
            desc1.putReference(cTID('null'), ref1);
            var desc2 = new ActionDescriptor();
            var list1 = new ActionList();
            var desc3 = new ActionDescriptor();
            var ref2 = new ActionReference();
            ref2.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Gry '));
            desc3.putReference(cTID('Chnl'), ref2);
            desc3.putInteger(cTID('SrcB'), 0);
            desc3.putInteger(cTID('Srcl'), 0);
            desc3.putInteger(cTID('SrcW'), 255);
            desc3.putInteger(cTID('Srcm'), 255);
            desc3.putInteger(cTID('DstB'), 125);
            desc3.putInteger(cTID('Dstl'), 255);
            desc3.putInteger(cTID('DstW'), 255);
            desc3.putInteger(cTID('Dstt'), 255);
            list1.putObject(cTID('Blnd'), desc3);
            desc2.putList(cTID('Blnd'), list1);
            var desc4 = new ActionDescriptor();
            desc4.putUnitDouble(cTID('Scl '), cTID('#Prc'), 416.666666666667);
            desc2.putObject(cTID('Lefx'), cTID('Lefx'), desc4);
            desc1.putObject(cTID('T   '), cTID('Lyr '), desc2);
            executeAction(cTID('setd'), desc1, dialogMode);
        };

        // Make
        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.putClass(sTID("layerSection"));
            desc1.putReference(cTID('null'), ref1);
            var ref2 = new ActionReference();
            ref2.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
            desc1.putReference(cTID('From'), ref2);
            executeAction(cTID('Mk  '), desc1, dialogMode);
        };

        // Set
        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(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
            desc1.putReference(cTID('null'), ref1);
            var desc2 = new ActionDescriptor();
            desc2.putString(cTID('Nm  '), "Mattifier Powder");
            desc1.putObject(cTID('T   '), cTID('Lyr '), desc2);
            executeAction(cTID('setd'), desc1, dialogMode);
        };

        // Make
        function step6(enabled, withDialog) {
            if (enabled != undefined && !enabled)
                return;
            var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
            var desc1 = new ActionDescriptor();
            desc1.putClass(cTID('Nw  '), cTID('Chnl'));
            var ref1 = new ActionReference();
            ref1.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Msk '));
            desc1.putReference(cTID('At  '), ref1);
            desc1.putEnumerated(cTID('Usng'), cTID('UsrM'), cTID('HdAl'));
            executeAction(cTID('Mk  '), desc1, dialogMode);
        };

        // Select
        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.putClass(cTID('PbTl'));
            desc1.putReference(cTID('null'), ref1);
            executeAction(cTID('slct'), desc1, dialogMode);
        };

        // Set
        function step8(enabled, withDialog) {
            if (enabled != undefined && !enabled)
                return;
            var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
            var desc1 = new ActionDescriptor();
            var ref1 = new ActionReference();
            ref1.putProperty(cTID('Clr '), cTID('FrgC'));
            desc1.putReference(cTID('null'), ref1);
            var desc2 = new ActionDescriptor();
            desc2.putUnitDouble(cTID('H   '), cTID('#Ang'), 0);
            desc2.putDouble(cTID('Strt'), 0);
            desc2.putDouble(cTID('Brgh'), 100);
            desc1.putObject(cTID('T   '), cTID('HSBC'), desc2);
            desc1.putString(cTID('Srce'), "photoshopPicker");
            executeAction(cTID('setd'), desc1, dialogMode);
        };

        // Set
        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.putProperty(cTID('Clr '), cTID('BckC'));
            desc1.putReference(cTID('null'), ref1);
            var desc2 = new ActionDescriptor();
            desc2.putUnitDouble(cTID('H   '), cTID('#Ang'), 0);
            desc2.putDouble(cTID('Strt'), 0);
            desc2.putDouble(cTID('Brgh'), 0);
            desc1.putObject(cTID('T   '), cTID('HSBC'), desc2);
            desc1.putString(cTID('Srce'), "photoshopPicker");
            executeAction(cTID('setd'), desc1, dialogMode);
        };

        // Stop
        function step10(enabled, withDialog) {
            if (enabled != undefined && !enabled)
                return;
            var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
            var desc1 = new ActionDescriptor();
            desc1.putString(cTID('Msge'),);
            desc1.putBoolean(cTID('Cntn'), true);
            executeAction(cTID('Stop'), desc1, dialogMode);
        };

        // Stop
        function step11(enabled, withDialog) {
            if (enabled != undefined && !enabled)
                return;
            var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
            var desc1 = new ActionDescriptor();
            desc1.putString(cTID('Msge'),);
            desc1.putBoolean(cTID('Cntn'), true);
            executeAction(cTID('Stop'), desc1, dialogMode);
        };

        step1();      // Make
        step2();      // Set
        step3();      // Set
        step4();      // Make
        step5();      // Set
        step6();      // Make
        step7();      // Select
        step8();      // Set
        step9();      // Set
        step10(true, true);      // Stop
        step11(true, true);      // Stop
    },
};

3.代码转执行

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

4.作者答疑


  如有疑问,请留言。

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐