Photoshop插件--RGB通道--蓝色--反相--脚本开发--PS插件
作者:互联网
文章目录
PS是一款栅格图像编辑软件,具有许多强大的功能,本文演示如何通过脚本实现RGB通道蓝色和反相相关功能,展示从互联网收集而来的一个小插件,供大家学习交流,请勿用于商业用途。
1.插件界面
本文界面是一系列功能的一部分,将逐步展示,但是功能界面是共同的,如下图所示:
2.关键代码
2.1 蓝色
大家可通过源代码阅读,来掌握相关技巧,源代码如下:
if (ScriptUI.environment.keyboardState.shiftKey) {
function Blue() {
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.Layer);
desc1.putReference(PSString.Null, ref1);
executeAction(PSEvent.Make, desc1, dialogMode);
}
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled) {
return;
}
var dialogMode = withDialog ? DialogModes.ALL : DialogModes.NO;
var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(PSClass.Channel, PSClass.Channel, PSEnum.Blue);
ref1.putEnumerated(PSClass.Layer, PSType.Ordinal, PSEnum.Merged);
desc2.putReference(PSKey.To, ref1);
desc1.putObject(PSKey.With, PSClass.Calculation, desc2);
executeAction(sTID("applyImageEvent"), desc1, 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.Layer, PSType.Ordinal, PSEnum.Target);
desc1.putReference(PSString.Null, ref1);
var desc2 = new ActionDescriptor();
desc2.putString(PSKey.Name, "Blue_Channel");
desc1.putObject(PSKey.To, PSClass.Layer, 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.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);
}
step1();
step2();
step3();
step4();
}
cTID = function(s) {
return app.charIDToTypeID(s);
};
sTID = function(s) {
return app.stringIDToTypeID(s);
};
Blue.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.Calculation = cTID("Clcl");
PSClass.Channel = cTID("Chnl");
PSClass.Layer = cTID("Lyr ");
PSEnum.Blue = cTID("Bl ");
PSEnum.Green = cTID("Grn ");
PSEnum.Merged = cTID("Mrgd");
PSEnum.Red = cTID("Rd ");
PSEnum.Target = cTID("Trgt");
PSEvent.Make = cTID("Mk ");
PSEvent.Set = cTID("setd");
PSKey.Color = cTID("Clr ");
PSKey.Name = cTID("Nm ");
PSKey.To = cTID("T ");
PSKey.With = cTID("With");
PSString.Null = sTID("null");
PSType.Ordinal = cTID("Ordn");
};
Blue.loadSymbols();
Blue.main = function() {
Blue();
};
Blue.main();
var idsetd = charIDToTypeID("setd");
var desc4 = new ActionDescriptor();
var idnull = charIDToTypeID("null");
var ref2 = new ActionReference();
var idLyr = charIDToTypeID("Lyr ");
var idOrdn = charIDToTypeID("Ordn");
var idTrgt = charIDToTypeID("Trgt");
ref2.putEnumerated(idLyr, idOrdn, idTrgt);
desc4.putReference(idnull, ref2);
var idT = charIDToTypeID("T ");
var desc5 = new ActionDescriptor();
var idMd = charIDToTypeID("Md ");
var idBlnM = charIDToTypeID("BlnM");
var idSftL = charIDToTypeID("SftL");
desc5.putEnumerated(idMd, idBlnM, idSftL);
var idLyr = charIDToTypeID("Lyr ");
desc4.putObject(idT, idLyr, desc5);
executeAction(idsetd, desc4, DialogModes.NO);
} else {
function Blue() {
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.Layer);
desc1.putReference(PSString.Null, ref1);
executeAction(PSEvent.Make, desc1, dialogMode);
}
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled) {
return;
}
var dialogMode = withDialog ? DialogModes.ALL : DialogModes.NO;
var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(PSClass.Channel, PSClass.Channel, PSEnum.Blue);
ref1.putEnumerated(PSClass.Layer, PSType.Ordinal, PSEnum.Merged);
desc2.putReference(PSKey.To, ref1);
desc1.putObject(PSKey.With, PSClass.Calculation, desc2);
executeAction(sTID("applyImageEvent"), desc1, 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.Layer, PSType.Ordinal, PSEnum.Target);
desc1.putReference(PSString.Null, ref1);
var desc2 = new ActionDescriptor();
desc2.putString(PSKey.Name, "Blue_Channel");
desc1.putObject(PSKey.To, PSClass.Layer, 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.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);
}
step1();
step2();
step3();
step4();
}
cTID = function(s) {
return app.charIDToTypeID(s);
};
sTID = function(s) {
return app.stringIDToTypeID(s);
};
Blue.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.Calculation = cTID("Clcl");
PSClass.Channel = cTID("Chnl");
PSClass.Layer = cTID("Lyr ");
PSEnum.Blue = cTID("Bl ");
PSEnum.Green = cTID("Grn ");
PSEnum.Merged = cTID("Mrgd");
PSEnum.Red = cTID("Rd ");
PSEnum.Target = cTID("Trgt");
PSEvent.Make = cTID("Mk ");
PSEvent.Set = cTID("setd");
PSKey.Color = cTID("Clr ");
PSKey.Name = cTID("Nm ");
PSKey.To = cTID("T ");
PSKey.With = cTID("With");
PSString.Null = sTID("null");
PSType.Ordinal = cTID("Ordn");
};
Blue.loadSymbols();
Blue.main = function() {
Blue();
};
Blue.main();
}
2.2 反相
大家可通过源代码阅读,来掌握相关技巧,源代码如下:
//
//==================== Invert ==============
//
function Invert() {
// Invert
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
executeAction(PSEvent.Invert, undefined, dialogMode);
};
step1(); // Invert
};
cTID = function (s) {
return app.charIDToTypeID(s);
};
sTID = function (s) {
return app.stringIDToTypeID(s);
};
//
// Invert.loadSymbols
// Loading up the symbol definitions like this makes it possible
// to include several of these generated files in one master file
// provided a prefix is specified other than the default. It also
// skips the definitions if PSConstants has already been loaded.
//
Invert.loadSymbols = function () {
var dbgLevel = $.level;
$.level = 0;
try {
PSConstants;
return; // only if PSConstants is defined
} 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 () {
};
}
// We may still end up duplicating some of the following definitions
// but at least we don't redefine PSClass, etc... and wipe out others
PSClass.AdjustmentLayer = cTID('AdjL');
PSClass.Calculation = cTID('Clcl');
PSClass.Channel = cTID('Chnl');
PSClass.ChannelMatrix = cTID('ChMx');
PSClass.ChannelMixer = cTID('ChnM');
PSClass.Curves = cTID('Crvs');
PSClass.CurvesAdjustment = cTID('CrvA');
PSClass.HueSatAdjustmentV2 = cTID('Hst2');
PSClass.HueSaturation = cTID('HStr');
PSClass.Layer = cTID('Lyr ');
PSClass.Mask = cTID('Msk ');
PSClass.PaintbrushTool = cTID('PbTl');
PSClass.Point = cTID('Pnt ');
PSClass.RGBColor = cTID('RGBC');
PSClass.Version = cTID('Vrsn');
PSEnum.All = cTID('Al ');
PSEnum.AntiAliasNone = cTID('Anno');
PSEnum.Best = cTID('Bst ');
PSEnum.Bicubic = cTID('Bcbc');
PSEnum.Blue = cTID('Bl ');
PSEnum.ColorBurn = cTID('CBrn');
PSEnum.Composite = cTID('Cmps');
PSEnum.ForegroundColor = cTID('FrgC');
PSEnum.GaussianDistribution = cTID('Gsn ');
PSEnum.HideAll = cTID('HdAl');
PSEnum.Luminosity = cTID('Lmns');
PSEnum.Merged = cTID('Mrgd');
PSEnum.Midtones = cTID('Mdtn');
PSEnum.Multiply = cTID('Mltp');
PSEnum.None = cTID('None');
PSEnum.Normal = cTID('Nrml');
PSEnum.Overlay = cTID('Ovrl');
PSEnum.QCSAverage = cTID('Qcsa');
PSEnum.RGB = cTID('RGB ');
PSEnum.Screen = cTID('Scrn');
PSEnum.SoftLight = cTID('SftL');
PSEnum.Target = cTID('Trgt');
PSEnum.Zoom = cTID('Zm ');
PSEvent.Copy = cTID('copy');
PSEvent.Delete = cTID('Dlt ');
PSEvent.Duplicate = cTID('Dplc');
PSEvent.Exchange = cTID('Exch');
PSEvent.Fill = cTID('Fl ');
PSEvent.Hide = cTID('Hd ');
PSEvent.Invert = cTID('Invr');
PSEvent.Make = cTID('Mk ');
PSEvent.Paste = cTID('past');
PSEvent.Reset = cTID('Rset');
PSEvent.Select = cTID('slct');
PSEvent.Set = cTID('setd');
PSEvent.Show = cTID('Shw ');
PSEvent.Transform = cTID('Trnf');
PSKey.Adjustment = cTID('Adjs');
PSKey.Amount = cTID('Amnt');
PSKey.AntiAlias = cTID('AntA');
PSKey.At = cTID('At ');
PSKey.BeginRamp = cTID('BgnR');
PSKey.BeginSustain = cTID('BgnS');
PSKey.BlurMethod = cTID('BlrM');
PSKey.BlurQuality = cTID('BlrQ');
PSKey.Color = cTID('Clr ');
PSKey.Colorize = cTID('Clrz');
PSKey.Colors = cTID('Clrs');
PSKey.Constrain = cTID('Cnst');
PSKey.Curve = cTID('Crv ');
PSKey.Distribution = cTID('Dstr');
PSKey.EndRamp = cTID('EndR');
PSKey.EndSustain = cTID('EndS');
PSKey.FillNeutral = cTID('FlNt');
PSKey.FilterLayerRandomSeed = cTID('FlRs');
PSKey.FreeTransformCenterState = cTID('FTcs');
PSKey.From = cTID('From');
PSKey.Gray = cTID('Gry ');
PSKey.Green = cTID('Grn ');
PSKey.Height = cTID('Hght');
PSKey.Horizontal = cTID('Hrzn');
PSKey.Hue = cTID('H ');
PSKey.Interpolation = cTID('Intr');
PSKey.Lightness = cTID('Lght');
PSKey.LocalRange = cTID('LclR');
PSKey.MakeVisible = cTID('MkVs');
PSKey.Mode = cTID('Md ');
PSKey.Monochromatic = cTID('Mnch');
PSKey.Name = cTID('Nm ');
PSKey.New = cTID('Nw ');
PSKey.Noise = cTID('Nose');
PSKey.Offset = cTID('Ofst');
PSKey.Opacity = cTID('Opct');
PSKey.Radius = cTID('Rds ');
PSKey.Red = cTID('Rd ');
PSKey.Start = cTID('Strt');
PSKey.Threshold = cTID('Thsh');
PSKey.To = cTID('T ');
PSKey.Type = cTID('Type');
PSKey.Using = cTID('Usng');
PSKey.Vertical = cTID('Vrtc');
PSKey.Width = cTID('Wdth');
PSKey.With = cTID('With');
PSString.Null = sTID('null');
PSString.addToSelectionContinuous = sTID('addToSelectionContinuous');
PSString.contentLayer = sTID('contentLayer');
PSString.layerGroup = sTID('layerSection');
PSString.presetKind = sTID('presetKind');
PSString.presetKindCustom = sTID('presetKindCustom');
PSString.presetKindDefault = sTID('presetKindDefault');
PSString.presetKindType = sTID('presetKindType');
PSString.selection = sTID('selection');
PSString.selectionModifier = sTID('selectionModifier');
PSString.selectionModifierType = sTID('selectionModifierType');
PSString.solidColorLayer = sTID('solidColorLayer');
PSType.AntiAlias = cTID('Annt');
PSType.BlendMode = cTID('BlnM');
PSType.FillContents = cTID('FlCn');
PSType.Interpolation = cTID('Intp');
PSType.Ordinal = cTID('Ordn');
PSType.QuadCenterState = cTID('QCSt');
PSType.UserMaskOptions = cTID('UsrM');
PSUnit.Distance = cTID('#Rlt');
PSUnit.Percent = cTID('#Prc');
PSUnit.Pixels = cTID('#Pxl');
};
Invert.loadSymbols(); // load up our symbols
//=========================================
// Invert.main
//=========================================
//
Invert.main = function () {
Invert();
};
Invert.main();
// EOF
3.作者寄语
合理的脚本代码可以有效的提高工作效率,减少重复劳动。
欢迎光临知了软件开发网络平台,本公司定制开发各类软件,主要方向为桌面专业软件开发、插件定制开发、微信小程序(各类小程序)、网站定制开发和App开发,桌面软件主要包括文字图形识别类软件,信息管理类软件,3D打印类软件,视频类软件以及其它涉及专业的各类图形图像处理软件。插件包含AE插件,AI插件,PS插件,PDF插件,3DMAX插件以及Word,Excel等Office插件开发。详情请咨询,微信QQ:312117271,手机:18928899728,邮箱: anjingzhi_sea@163.com.
公司网址:http://www.zhiliaos.com
标签:function,插件,--,PSEnum,PSKey,PSClass,var,cTID,反相 来源: https://blog.csdn.net/weixin_42247427/article/details/122027881