Photoshop插件--逆时针旋转90度--旋转180度--顺时针旋转90度--脚本开发--PS插件

文章目录


  PS是一款栅格图像编辑软件,具有许多强大的功能,本文演示如何通过脚本实现逆时针旋转90度、旋转180度和顺时针旋转90度相关功能,展示从互联网收集而来的一个小插件,供大家学习交流,请勿用于商业用途。

1.插件界面

  本文界面是一系列功能的一部分,将逐步展示,但是功能界面是共同的,如下图所示:
Photoshop插件--逆时针旋转90度--旋转180度--顺时针旋转90度--脚本开发--PS插件

2.关键代码

2.1 逆时针旋转90度

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

//
//==================== Rotate <=90 ==============
//
function Rotate__90() {
    // Rotate
    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.putUnitDouble(PSKey.Angle, PSUnit.Angle, -90);
        executeAction(PSEvent.Rotate, desc1, dialogMode);
    };

    step1();      // Rotate
};


cTID = function (s) {
    return app.charIDToTypeID(s);
};
sTID = function (s) {
    return app.stringIDToTypeID(s);
};

//
// Rotate__90.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.
//
Rotate__90.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.Document = cTID('Dcmn');
    PSEnum.First = cTID('Frst');
    PSEvent.Rotate = cTID('Rtte');
    PSKey.Angle = cTID('Angl');
    PSString.Null = sTID('null');
    PSType.Ordinal = cTID('Ordn');
    PSUnit.Angle = cTID('#Ang');
};

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


//=========================================
//                    Rotate__90.main
//=========================================
//

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

Rotate__90.main();

// EOF

2.2 旋转180度

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

//
// Generated Tue Feb 17 2015 14:47:21 GMT+0600
//

//
//==================== Rotate 180 ==============
//
function Rotate180() {
    // Rotate
    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.putUnitDouble(PSKey.Angle, PSUnit.Angle, 180);
        executeAction(PSEvent.Rotate, desc1, dialogMode);
    };

    step1();      // Rotate
};


cTID = function (s) {
    return app.charIDToTypeID(s);
};
sTID = function (s) {
    return app.stringIDToTypeID(s);
};

//
// Rotate180.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.
//
Rotate180.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.Document = cTID('Dcmn');
    PSEnum.First = cTID('Frst');
    PSEvent.Rotate = cTID('Rtte');
    PSKey.Angle = cTID('Angl');
    PSString.Null = sTID('null');
    PSType.Ordinal = cTID('Ordn');
    PSUnit.Angle = cTID('#Ang');
};

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

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

Rotate180.main();

// EOF

2.3 顺时针旋转90度

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

//
//==================== Rotate 90=> ==============
//
function Rotate90() {
    // Rotate
    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.putUnitDouble(PSKey.Angle, PSUnit.Angle, 90);
        executeAction(PSEvent.Rotate, desc1, dialogMode);
    };

    step1();      // Rotate
};


cTID = function (s) {
    return app.charIDToTypeID(s);
};
sTID = function (s) {
    return app.stringIDToTypeID(s);
};

//
// Rotate90.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.
//
Rotate90.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.Document = cTID('Dcmn');
    PSEnum.First = cTID('Frst');
    PSEvent.Rotate = cTID('Rtte');
    PSKey.Angle = cTID('Angl');
    PSString.Null = sTID('null');
    PSType.Ordinal = cTID('Ordn');
    PSUnit.Angle = cTID('#Ang');
};

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


//=========================================
//                    Rotate90.main
//=========================================
//

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

Rotate90.main();

// EOF

3.作者寄语

  合理的脚本代码可以有效的提高工作效率,减少重复劳动。


  欢迎光临知了软件开发网络平台,本公司定制开发各类软件,主要方向为桌面专业软件开发、插件定制开发、微信小程序(各类小程序)、网站定制开发和App开发,桌面软件主要包括文字图形识别类软件,信息管理类软件,3D打印类软件,视频类软件以及其它涉及专业的各类图形图像处理软件。插件包含AE插件,AI插件,PS插件,PDF插件,3DMAX插件以及Word,Excel等Office插件开发。详情请咨询,微信QQ:312117271,手机:18928899728,邮箱: anjingzhi_sea@163.com.
公司网址:http://www.zhiliaos.com

上一篇:笔记:读Contextual String Embeddings for Sequence Labeling


下一篇:LTE无线网络全网优化评估手段