Photoshop插件--创建中间调通道蒙板--脚本开发--PS插件

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

1.插件界面

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


d20412ec35fd4e098033671909a2809c.png

2.关键代码-创建中间调通道蒙板

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

// jamEngine.jsxinc v4.4 (minified)
if (typeof jamEngine !== 'object') {
    var jamEngine = {};
    (function () {
        var that;
        jamEngine.meaningfulIds = false;
        jamEngine.parseFriendly = false;
        var conflictingStringIdStrs = {
            "'Algn'": ["align", "alignment"],
            "'AntA'": ["antiAlias", "antiAliasedPICTAcquire"],
            "'BckL'": ["backgroundLayer", "backgroundLevel"],
            "'BlcG'": ["blackGenerationType", "blackGenerationCurve"],
            "'BlcL'": ["blackLevel", "blackLimit"],
            "'Blks'": ["blacks", "blocks"],
            "'BlrM'": ["blurMethod", "blurMore"],
            "'BrgC'": ["brightnessEvent", "brightnessContrast"],
            "'BrsD'": ["brushDetail", "brushesDefine"],
            "'Brsh'": ["brush", "brushes"],
            "'Clcl'": ["calculation", "calculations"],
            "'ClrP'": ["colorPalette", "coloredPencil"],
            "'Cnst'": ["constant", "constrain"],
            "'CntC'": ["centerCropMarks", "conteCrayon"],
            "'Cntr'": ["center", "contrast"],
            "'CrtD'": ["createDroplet", "createDuplicate"],
            "'CstP'": ["customPalette", "customPhosphors"],
            "'Cstm'": ["custom", "customPattern"],
            "'Drkn'": ["darken", "darkness"],
            "'Dstr'": ["distort", "distortion", "distribute", "distribution"],
            "'Dstt'": ["desaturate", "destWhiteMax"],
            "'FlIn'": ["fileInfo", "fillInverse"],
            "'Gd  '": ["good", "guide"],
            "'GnrP'": ["generalPreferences", "generalPrefs", "preferencesClass"],
            "'GrSt'": ["grainStippled", "graySetup"],
            "'Grdn'": ["gradientClassEvent", "gridMinor"],
            "'Grn '": ["grain", "green"],
            "'Grns'": ["graininess", "greens"],
            "'HstP'": ["historyPreferences", "historyPrefs"],
            "'HstS'": ["historyState", "historyStateSourceType"],
            "'ImgP'": ["imageCachePreferences", "imagePoint"],
            "'In  '": ["in", "stampIn"],
            "'IntW'": ["interfaceWhite", "intersectWith"],
            "'Intr'": ["interfaceIconFrameDimmed", "interlace", "interpolation", "intersect"],
            "'JPEG'": ["JPEG", "JPEGFormat"],
            "'LghD'": ["lightDirection", "lightDirectional"],
            "'LghO'": ["lightOmni", "lightenOnly"],
            "'LghS'": ["lightSource", "lightSpot"],
            "'Lns '": ["lens", "lines"],
            "'Mgnt'": ["magenta", "magentas"],
            "'MrgL'": ["mergeLayers", "mergedLayers"],
            "'Mxm '": ["maximum", "maximumQuality"],
            "'NTSC'": ["NTSC", "NTSCColors"],
            "'NmbL'": ["numberOfLayers", "numberOfLevels"],
            "'PlgP'": ["pluginPicker", "pluginPrefs"],
            "'Pncl'": ["pencilEraser", "pencilWidth"],
            "'Pnt '": ["paint", "point"],
            "'Prsp'": ["perspective", "perspectiveIndex"],
            "'PrvM'": ["previewMacThumbnail", "previewMagenta"],
            "'Pstr'": ["posterization", "posterize"],
            "'RGBS'": ["RGBSetup", "RGBSetupSource"],
            "'Rds '": ["radius", "reds"],
            "'ScrD'": ["scratchDisks", "screenDot"],
            "'ShdI'": ["shadingIntensity", "shadowIntensity"],
            "'ShpC'": ["shapeCurveType", "shapingCurve"],
            "'ShrE'": ["sharpenEdges", "shearEd"],
            "'Shrp'": ["sharpen", "sharpness"],
            "'SplC'": ["splitChannels", "supplementalCategories"],
            "'Spot'": ["spot", "spotColor"],
            "'SprS'": ["separationSetup", "sprayedStrokes"],
            "'StrL'": ["strokeLength", "strokeLocation"],
            "'Strt'": ["saturation", "start"],
            "'TEXT'": ["char", "textType"],
            "'TIFF'": ["TIFF", "TIFFFormat"],
            "'TglO'": ["toggleOptionsPalette", "toggleOthers"],
            "'TrnG'": ["transparencyGamutPreferences", "transparencyGrid", "transparencyGridSize"],
            "'TrnS'": ["transferSpec", "transparencyShape", "transparencyStop"],
            "'Trns'": ["transparency", "transparent"],
            "'TxtC'": ["textClickPoint", "textureCoverage"],
            "'TxtF'": ["textureFile", "textureFill"],
            "'UsrM'": ["userMaskEnabled", "userMaskOptions"],
            "'c@#^'": ["inherits", "pInherits"],
            "'comp'": ["comp", "sInt64"],
            "'doub'": ["floatType", "IEEE64BitFloatingPoint", "longFloat"],
            "'long'": ["integer", "longInteger", "sInt32"],
            "'magn'": ["magnitude", "uInt32"],
            "'null'": ["null", "target"],
            "'shor'": ["sInt16", "sMInt", "shortInteger"],
            "'sing'": ["IEEE32BitFloatingPoint", "sMFloat", "shortFloat"]
        };
        jamEngine.getConflictingStringIdStrs = function (charIdStr) {
            return conflictingStringIdStrs[charIdStr] || null;
        };
        jamEngine.uniIdStrToId = function (uniIdStr) {
            var id = 0;
            if (typeof uniIdStr === 'string') {
                if ((uniIdStr.length === (1 + 4 + 1)) && (uniIdStr.charAt(0) === "'") && (uniIdStr.charAt(5) === "'")) {
                    id = app.charIDToTypeID(uniIdStr.substring(1, 5));
                } else {
                    id = app.stringIDToTypeID(uniIdStr);
                }
            }
            return id;
        };
        var smallestHashValue = app.charIDToTypeID("    ");
        jamEngine.idToUniIdStrs = function (id) {
            var charIdStr = "";
            var stringIdStr = app.typeIDToStringID(id);
            if (id >= smallestHashValue) {
                charIdStr = "'" + app.typeIDToCharID(id) + "'";
                if (stringIdStr !== "") {
                    if (charIdStr in conflictingStringIdStrs) {
                        stringIdStr = conflictingStringIdStrs[charIdStr];
                    }
                }
            }
            return [charIdStr, stringIdStr];
        };
        jamEngine.equivalentUniIdStrs = function (uniIdStr1, uniIdStr2) {
            return this.uniIdStrToId(uniIdStr1) === this.uniIdStrToId(uniIdStr2);
        };

        function putInReference(ref, containers) {
            if (containers.constructor === Array) {
                var count = containers.length;
                for (var i = 0; i < count; i++) {
                    var container = that.parseCompact(containers[i]);
                    var desiredClassId = that.uniIdStrToId(container[0]);
                    var typedValue = that.parseCompact(container[1]);
                    var form = typedValue[0];
                    var value = typedValue[1];
                    switch (form) {
                        case"<class>":
                            ref.putClass(desiredClassId);
                            break;
                        case"<enumerated>":
                            var enumerated = that.parseCompact(value);
                            ref.putEnumerated(desiredClassId, that.uniIdStrToId(enumerated[0]), that.uniIdStrToId(enumerated[1]));
                            break;
                        case"<identifier>":
                            ref.putIdentifier(desiredClassId, value);
                            break;
                        case"<index>":
                            ref.putIndex(desiredClassId, value);
                            break;
                        case"<name>":
                            ref.putName(desiredClassId, value);
                            break;
                        case"<offset>":
                            ref.putOffset(desiredClassId, value);
                            break;
                        case"<property>":
                            ref.putProperty(desiredClassId, that.uniIdStrToId(value));
                            break;
                        default:
                            throw new Error("[jamEngine putInReference] Unknown reference form: " + form);
                            break;
                    }
                }
            } else {
                throw new Error("[jamEngine putInReference] JavaScript array expected");
            }
        }

        function putInList(list, items) {
            if (items.constructor === Array) {
                var count = items.length;
                for (var i = 0; i < count; i++) {
                    var item = that.parseCompact(items[i]);
                    var type = item[0];
                    var value = item[1];
                    switch (type) {
                        case"<boolean>":
                            list.putBoolean(value);
                            break;
                        case"<class>":
                            list.putClass(that.uniIdStrToId(value));
                            break;
                        case"<data>":
                            list.putData(value);
                            break;
                        case"<double>":
                            list.putDouble(value);
                            break;
                        case"<enumerated>":
                            var enumerated = that.parseCompact(value);
                            list.putEnumerated(that.uniIdStrToId(enumerated[0]), that.uniIdStrToId(enumerated[1]));
                            break;
                        case"<integer>":
                            list.putInteger(value);
                            break;
                        case"<largeInteger>":
                            list.putLargeInteger(value);
                            break;
                        case"<list>":
                            var actionList = new ActionList();
                            putInList(actionList, value);
                            list.putList(actionList);
                            break;
                        case"<object>":
                            var object = that.parseCompact(value);
                            if (object[1]) {
                                var actionDescriptor = new ActionDescriptor();
                                putInDescriptor(actionDescriptor, object[1]);
                                list.putObject(that.uniIdStrToId(object[0]), actionDescriptor);
                            } else {
                                list.putClass(that.uniIdStrToId(object[0]));
                            }
                            break;
                        case"<path>":
                            var fileRef = new File(value);
                            list.putPath(fileRef);
                            break;
                        case"<reference>":
                            var actionReference = new ActionReference();
                            putInReference(actionReference, value);
                            list.putReference(actionReference);
                            break;
                        case"<string>":
                            list.putString(value);
                            break;
                        case"<unitDouble>":
                            var unitDouble = that.parseCompact(value);
                            list.putUnitDouble(that.uniIdStrToId(unitDouble[0]), unitDouble[1]);
                            break;
                        default:
                            throw new Error("[jamEngine putInList] Unknown list type: " + type);
                            break;
                    }
                }
            } else {
                throw new Error("[jamEngine putInList] JavaScript array expected");
            }
        }

        function putInDescriptor(desc, members) {
            if (members.constructor === Object) {
                for (var key in members) {
                    if (members.hasOwnProperty(key)) {
                        var keyID = that.uniIdStrToId(key);
                        var member = that.parseCompact(members[key]);
                        var type = member[0];
                        var value = member[1];
                        switch (type) {
                            case"<boolean>":
                                desc.putBoolean(keyID, value);
                                break;
                            case"<class>":
                                desc.putClass(keyID, that.uniIdStrToId(value));
                                break;
                            case"<data>":
                                desc.putData(keyID, value);
                                break;
                            case"<double>":
                                desc.putDouble(keyID, value);
                                break;
                            case"<enumerated>":
                                var enumerated = that.parseCompact(value);
                                desc.putEnumerated(keyID, that.uniIdStrToId(enumerated[0]), that.uniIdStrToId(enumerated[1]));
                                break;
                            case"<integer>":
                                desc.putInteger(keyID, value);
                                break;
                            case"<largeInteger>":
                                desc.putLargeInteger(keyID, value);
                                break;
                            case"<list>":
                                var actionList = new ActionList();
                                putInList(actionList, value);
                                desc.putList(keyID, actionList);
                                break;
                            case"<object>":
                                var object = that.parseCompact(value);
                                if (object[1]) {
                                    var actionDescriptor = new ActionDescriptor();
                                    putInDescriptor(actionDescriptor, object[1]);
                                    desc.putObject(keyID, that.uniIdStrToId(object[0]), actionDescriptor);
                                } else {
                                    desc.putClass(keyID, that.uniIdStrToId(object[0]));
                                }
                                break;
                            case"<path>":
                                var fileRef = new File(value);
                                desc.putPath(keyID, fileRef);
                                break;
                            case"<reference>":
                                var actionReference = new ActionReference();
                                putInReference(actionReference, value);
                                desc.putReference(keyID, actionReference);
                                break;
                            case"<string>":
                                desc.putString(keyID, value);
                                break;
                            case"<unitDouble>":
                                var unitDouble = that.parseCompact(value);
                                desc.putUnitDouble(keyID, that.uniIdStrToId(unitDouble[0]), unitDouble[1]);
                                break;
                            default:
                                throw new Error("[jamEngine putInDescriptor] Unknown descriptor type: " + type);
                                break;
                        }
                    }
                }
            } else {
                throw new Error("[jamEngine putInDescriptor] JavaScript object expected");
            }
        }

}

3.作者答疑

  代码数量太多,需要完整代码,请留言。


  合理的脚本代码可以有效的提高工作效率,减少重复劳动。

提示: 作者知了-联系方式1
提示: 作者知了-联系方式2

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,530评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 86,403评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,120评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,770评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,758评论 5 367
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,649评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,021评论 3 398
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,675评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,931评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,659评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,751评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,410评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,004评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,969评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,203评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,042评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,493评论 2 343

推荐阅读更多精彩内容