您当前的位置: 首页 > 

插件开发

暂无认证

  • 1浏览

    0关注

    492博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Photoshop插件-保存-横边≤1300点-脚本开发-PS插件

插件开发 发布时间:2022-03-26 08:58:17 ,浏览量:1

文章目录
    • 1.插件界面
    • 2.关键代码
    • 3.代码转执行
    • 4.作者答疑
  PS是一款栅格图像编辑软件,具有许多强大的功能,本文演示如何通过脚本实现横边≤1300点相关功能,展示从互联网收集而来的一个小插件,供大家学习交流,请勿用于商业用途。

1.插件界面

  本文界面是一系列功能的一部分,将逐步展示,但是功能界面是共同的,如下图所示: 在这里插入图片描述

2.关键代码

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

//
//==================== Horizontal ==============
//
function Horizontal() {
    // 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, "Horizontal 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.Width, 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.Width, 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);
};

//
// Horizontal.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.
//
Horizontal.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.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');
};

Horizontal.loadSymbols(); // load up our symbols


//=========================================
//                    Horizontal.main
//=========================================
//

Horizontal.main = function () {
    Horizontal();
};

Horizontal.main();
3.代码转执行

  使用记事本或者notepad++等文本编辑器,将代码拷贝至文本文件,然后修改后缀名为js或者jsx,最后再PS软件菜单文件》脚本》浏览,点执行即可,也可以将脚本放在预设文件夹内,会显示再脚本下的二级子菜单。如下图所示: 在这里插入图片描述

4.作者答疑

  如有疑问,请留言。

关注
打赏
1665481431
查看更多评论
立即登录/注册

微信扫码登录

0.0401s