PS是一款栅格图像编辑软件,具有许多强大的功能,本文演示如何通过脚本实现竖边≤1300点相关功能,展示从互联网收集而来的一个小插件,供大家学习交流,请勿用于商业用途。
1.插件界面
本文界面是一系列功能的一部分,将逐步展示,但是功能界面是共同的,如下图所示:
2.关键代码
大家可通过源代码阅读,来掌握相关技巧,源代码如下:
//
//==================== Vertical ==============
//
function Vertical() {
// Duplicate
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.putEnumerated(PSClass.Document, PSType.Ordinal, PSEnum.First);
desc1.putReference(PSString.Null, ref1);
desc1.putString(PSKey.Name, "Vertical Save");
desc1.putBoolean(PSKey.Merged, true);
executeAction(PSEvent.Duplicate, desc1, dialogMode);
};
// Image Size
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putUnitDouble(PSKey.Height, PSUnit.Distance, 360);
desc1.putUnitDouble(PSKey.Resolution, PSUnit.Density, 300);
desc1.putBoolean(PSString.scaleStyles, true);
desc1.putBoolean(PSKey.ConstrainProportions, true);
desc1.putEnumerated(PSKey.Interpolation, PSType.Interpolation, PSString.bicubicSharper);
executeAction(sTID('imageSize'), desc1, dialogMode);
};
// Image Size
function step3(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putUnitDouble(PSKey.Height, PSUnit.Pixels, 1300);
desc1.putBoolean(PSString.scaleStyles, true);
desc1.putBoolean(PSKey.ConstrainProportions, true);
desc1.putEnumerated(PSKey.Interpolation, PSType.Interpolation, PSEnum.Bicubic);
executeAction(sTID('imageSize'), desc1, dialogMode);
};
// Save
function step4(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putInteger(PSKey.ExtendedQuality, 12);
desc2.putEnumerated(PSKey.MatteColor, PSKey.MatteColor, PSEnum.None);
desc1.putObject(PSKey.As, PSClass.JPEGFormat, desc2);
desc1.putPath(PSKey.In, new File("~/Desktop/Vertical Save.jpg"));
desc1.putInteger(PSKey.DocumentID, 1130);
executeAction(PSEvent.Save, desc1, dialogMode);
};
// Close
function step5(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putEnumerated(PSKey.Saving, PSType.YesNo, PSEnum.No);
executeAction(PSEvent.Close, desc1, dialogMode);
};
step1(); // Duplicate
step2(); // Image Size
step3(); // Image Size
step4(true, true); // Save
step5(); // Close
};
cTID = function (s) {
return app.charIDToTypeID(s);
};
sTID = function (s) {
return app.stringIDToTypeID(s);
};
//
// Vertical.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.
//
Vertical.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.Channel = cTID('Chnl');
PSClass.Curves = cTID('Crvs');
PSClass.CurvesAdjustment = cTID('CrvA');
PSClass.Document = cTID('Dcmn');
PSClass.JPEGFormat = cTID('JPEG');
PSClass.Layer = cTID('Lyr ');
PSClass.Mask = cTID('Msk ');
PSClass.PaintbrushTool = cTID('PbTl');
PSClass.Point = cTID('Pnt ');
PSClass.RGBColor = cTID('RGBC');
PSEnum.Bicubic = cTID('Bcbc');
PSEnum.Blue = cTID('Bl ');
PSEnum.Composite = cTID('Cmps');
PSEnum.Exclusion = cTID('Xclu');
PSEnum.First = cTID('Frst');
PSEnum.HideAll = cTID('HdAl');
PSEnum.Luminosity = cTID('Lmns');
PSEnum.No = cTID('N ');
PSEnum.None = cTID('None');
PSEnum.Overlay = cTID('Ovrl');
PSEnum.RGB = cTID('RGB ');
PSEnum.Target = cTID('Trgt');
PSEnum.Violet = cTID('Vlt ');
PSEvent.Close = cTID('Cls ');
PSEvent.Delete = cTID('Dlt ');
PSEvent.Duplicate = cTID('Dplc');
PSEvent.Invert = cTID('Invr');
PSEvent.Make = cTID('Mk ');
PSEvent.Save = cTID('save');
PSEvent.Select = cTID('slct');
PSEvent.Set = cTID('setd');
PSKey.Adjustment = cTID('Adjs');
PSKey.Amount = cTID('Amnt');
PSKey.As = cTID('As ');
PSKey.At = cTID('At ');
PSKey.Color = cTID('Clr ');
PSKey.ConstrainProportions = cTID('CnsP');
PSKey.Curve = cTID('Crv ');
PSKey.DocumentID = cTID('DocI');
PSKey.ExtendedQuality = cTID('EQlt');
PSKey.From = cTID('From');
PSKey.Green = cTID('Grn ');
PSKey.Height = cTID('Hght');
PSKey.Horizontal = cTID('Hrzn');
PSKey.In = cTID('In ');
PSKey.Interpolation = cTID('Intr');
PSKey.MakeVisible = cTID('MkVs');
PSKey.MatteColor = cTID('MttC');
PSKey.Merged = cTID('Mrgd');
PSKey.Mode = cTID('Md ');
PSKey.Name = cTID('Nm ');
PSKey.New = cTID('Nw ');
PSKey.Opacity = cTID('Opct');
PSKey.Radius = cTID('Rds ');
PSKey.Red = cTID('Rd ');
PSKey.Resolution = cTID('Rslt');
PSKey.Saving = cTID('Svng');
PSKey.Threshold = cTID('Thsh');
PSKey.To = cTID('T ');
PSKey.Type = cTID('Type');
PSKey.Using = cTID('Usng');
PSKey.Vertical = cTID('Vrtc');
PSKey.Width = cTID('Wdth');
PSString.Null = sTID('null');
PSString.addToSelectionContinuous = sTID('addToSelectionContinuous');
PSString.bicubicSharper = sTID('bicubicSharper');
PSString.contentLayer = sTID('contentLayer');
PSString.layerGroup = sTID('layerSection');
PSString.presetKind = sTID('presetKind');
PSString.presetKindDefault = sTID('presetKindDefault');
PSString.presetKindType = sTID('presetKindType');
PSString.scaleStyles = sTID('scaleStyles');
PSString.selectionModifier = sTID('selectionModifier');
PSString.selectionModifierType = sTID('selectionModifierType');
PSString.solidColorLayer = sTID('solidColorLayer');
PSType.BlendMode = cTID('BlnM');
PSType.Interpolation = cTID('Intp');
PSType.Ordinal = cTID('Ordn');
PSType.UserMaskOptions = cTID('UsrM');
PSType.YesNo = cTID('YsN ');
PSUnit.Density = cTID('#Rsl');
PSUnit.Distance = cTID('#Rlt');
PSUnit.Percent = cTID('#Prc');
PSUnit.Pixels = cTID('#Pxl');
};
Vertical.loadSymbols(); // load up our symbols
//=========================================
// Vertical.main
//=========================================
//
Vertical.main = function () {
Vertical();
};
Vertical.main();
// EOF
3.作者答疑
代码长度过长,如需全部项目或有疑问,请留言。
提示: 作者知了-联系方式1
提示: 作者知了-联系方式2