猿问

如何在 Photoshop 脚本中居中图层?

我的 Photoshop Canvas 是 900X600。


下面的函数采用X 层并复制X层。


它需要X 层复制,并在保持比例的同时将高度调整为 600 像素。var newdLayer


它需要 X 层,在保持比例的同时将宽度调整为 900 像素并应用高斯模糊。var blur.


然后它合并Layer X和Layer X copy。


问题是,如果X 层不在脚本的开头居中,那么它就会出现故障。


如何在脚本的开头将中心层添加到X层?


(function (){


var docRef = activeDocument

var blur = docRef.activeLayer;

var newdLayer = blur.duplicate();


    var startRulerUnits = app.preferences.rulerUnits;

    app.preferences.rulerUnits = Units.PIXELS;


    // since we resize based on the initial size of the source layer, 

    // we don't need to get the bounds twice

    var bounds = blur.bounds;

    var height = bounds[3].value - bounds[1].value;

    var width = bounds[2].value - bounds[0].value;

    // declare 2 different vars for your sizes (there are better ways to do this, but

    // since you say you aren't a JavaScript pro, I figured I'd keep it simple)

    var newSize600 = (100 / height) * 600;

    var newSize900 = (100 / width) * 900;

    // resize your layers

    newdLayer.resize(newSize600, newSize600, AnchorPosition.MIDDLECENTER);

    blur.resize(newSize900, newSize900, AnchorPosition.MIDDLECENTER);

    // apply blur

    blur.applyGaussianBlur(5);


    // below creates the group, moves the layers to it and merges them. Feel free to just include this part

    // at the end of your function if you don't want to use the modified code above. 


    // create a new layer set

    var groupOne = docRef.layerSets.add();


    // move the blur layer inside the layer set and name the layer for posterity

    blur.move(groupOne, ElementPlacement.INSIDE);

    blur.name = "blur";


    // move the newdLayer inside and rename

    newdLayer.move(groupOne, ElementPlacement.INSIDE);

    newdLayer.name = "newdLayer";


    // merge the layer set and name the new layer

    var mergedGroup = groupOne.merge();

    mergedGroup.name = "newdLayer + blur";


    app.preferences.rulerUnits = startRulerUnits;


})();


长风秋雁
浏览 176回答 1
1回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答