Photoshop插件--RGB通道--红色--绿色--脚本开发--PS插件
作者:互联网
文章目录
PS是一款栅格图像编辑软件,具有许多强大的功能,本文演示如何通过脚本实现RGB通道红色和绿色相关功能,展示从互联网收集而来的一个小插件,供大家学习交流,请勿用于商业用途。
1.插件界面
本文界面是一系列功能的一部分,将逐步展示,但是功能界面是共同的,如下图所示:
2.关键代码
2.1 红色
大家可通过源代码阅读,来掌握相关技巧,源代码如下:
if (ScriptUI.environment.keyboardState.shiftKey) {
function Red() {
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.Red);
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, "Red_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.Red);
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);
};
Red.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.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");
};
Red.loadSymbols();
Red.main = function() {
Red();
};
Red.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 Red() {
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.Red);
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, "Red_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.Red);
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);
};
Red.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.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");
};
Red.loadSymbols();
Red.main = function() {
Red();
};
Red.main();
}
2.2 绿色
大家可通过源代码阅读,来掌握相关技巧,源代码如下:
if (ScriptUI.environment.keyboardState.shiftKey) {
function Green() {
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.Green);
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.putEnumerated(PSKey.Color, PSKey.Color, PSEnum.Green);
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.putString(PSKey.Name, "Green_Channel");
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);
};
Green.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.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");
};
Green.loadSymbols();
Green.main = function() {
Green();
};
Green.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 Green() {
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.Green);
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.putEnumerated(PSKey.Color, PSKey.Color, PSEnum.Green);
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.putString(PSKey.Name, "Green_Channel");
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);
};
Green.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.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");
};
Green.loadSymbols();
Green.main = function() {
Green();
};
Green.main();
}
3.作者寄语
合理的脚本代码可以有效的提高工作效率,减少重复劳动。
欢迎光临知了软件开发网络平台,本公司定制开发各类软件,主要方向为桌面专业软件开发、插件定制开发、微信小程序(各类小程序)、网站定制开发和App开发,桌面软件主要包括文字图形识别类软件,信息管理类软件,3D打印类软件,视频类软件以及其它涉及专业的各类图形图像处理软件。插件包含AE插件,AI插件,PS插件,PDF插件,3DMAX插件以及Word,Excel等Office插件开发。详情请咨询,微信QQ:312117271,手机:18928899728,邮箱: anjingzhi_sea@163.com.
公司网址:http://www.zhiliaos.com
标签:function,Photoshop,插件,desc1,--,ref1,PSClass,var,cTID 来源: https://blog.csdn.net/weixin_42247427/article/details/122027793