为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

长风秋雁 2021-09-17 13:44:29
我的 Photoshop Canvas 是 900X600。下面的函数采用X 层并复制X层。它需要X 层复制,并在保持比例的同时将高度调整为 600 像素。var newdLayer它需要 X 层,在保持比例的同时将宽度调整为 900 像素并应用高斯模糊。var blur.然后它合并Layer X和Layer X copy。问题是,如果X 层不在脚本的开头居中,那么它就会出现故障。如何在脚本的开头将中心层添加到X层?(function (){var docRef = activeDocumentvar 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;})();
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 175 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号