PS是一款栅格图像编辑软件,具有许多强大的功能,本文演示如何通过脚本实现创建中间调通道蒙板相关功能,展示从互联网收集而来的一个小插件,供大家学习交流,请勿用于商业用途。
1.插件界面
本文界面是一系列功能的一部分,将逐步展示,但是功能界面是共同的,如下图所示:
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