如何在 Photoshop 文档中创建宽度为 100%、高度为 50% 的矩形?

发布于 2025-01-17 01:37:48 字数 1314 浏览 2 评论 0原文

Photoshop 脚本世界的新手,我想创建一个宽度为 Photoshop 文档的 100%、高度为 50% 的矩形?之后我想放入一些预定义的文本。这个想法是自动创建免责声明......你能帮助我吗?

对于第一步,我尝试修改该代码,但没有好的结果:)

activeDocument.suspendHistory('Resize', 'main()');

function main(){

if(!documents.length) return;

var Percent = 50; var OffsetX = 0; var OffsetY = 0; var Opacity = 100;

/////////////////////////////////////////////////////////////////////////////////////////////

var startRulerUnits = app.preferences.rulerUnits; app.preferences.rulerUnits = Units.PIXELS;

var myDoc = activeDocument;

var LB = myDoc.activeLayer.bounds; var docHeight = myDoc.height; var docWidth = myDoc.width;

var LHeight = Math.abs(LB[3].value) - Math.abs(LB[1].value); var LWidth = Math.abs(LB[2].value) - Math.abs(LB[0].value);

var percentageHeight = ((docHeight/LHeight)*Percent); var percentageWidth = ((docHeight/LHeight)*Percent); var percentageWidth = ((docWidth/LWidth)*Percent);

myDoc.activeLayer.resize(percentageWidth,percentageWidth,AnchorPosition.MIDDLECENTER);

var LB = myDoc.activeLayer.bounds;

var X = docWidth - Math.abs(LB[2].value); var Y = docHeight - Math.abs(LB[3].value);

X += OffsetX; Y += OffsetY;

activeDocument.activeLayer.translate(X,Y); activeDocument.activeLayer.opacity=Opacity; app.preferences.rulerUnits = startRulerUnits;

}

main();

New to the scripting world in photoshop, I would like to create a rectangle that is 100% of the width and 50% of the height of a photoshop document? And after i would like to put inside some predefined text. The idea is to automatise the creation of disclaimers... Can you help me?

For the first step, i'm trying to modify that code, but have no good result :)

activeDocument.suspendHistory('Resize', 'main()');

function main(){

if(!documents.length) return;

var Percent = 50; var OffsetX = 0; var OffsetY = 0; var Opacity = 100;

/////////////////////////////////////////////////////////////////////////////////////////////

var startRulerUnits = app.preferences.rulerUnits; app.preferences.rulerUnits = Units.PIXELS;

var myDoc = activeDocument;

var LB = myDoc.activeLayer.bounds; var docHeight = myDoc.height; var docWidth = myDoc.width;

var LHeight = Math.abs(LB[3].value) - Math.abs(LB[1].value); var LWidth = Math.abs(LB[2].value) - Math.abs(LB[0].value);

var percentageHeight = ((docHeight/LHeight)*Percent); var percentageWidth = ((docHeight/LHeight)*Percent); var percentageWidth = ((docWidth/LWidth)*Percent);

myDoc.activeLayer.resize(percentageWidth,percentageWidth,AnchorPosition.MIDDLECENTER);

var LB = myDoc.activeLayer.bounds;

var X = docWidth - Math.abs(LB[2].value); var Y = docHeight - Math.abs(LB[3].value);

X += OffsetX; Y += OffsetY;

activeDocument.activeLayer.translate(X,Y); activeDocument.activeLayer.opacity=Opacity; app.preferences.rulerUnits = startRulerUnits;

}

main();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱娆 2025-01-24 01:37:48

这是一个将创建文本的函数:

function create_text(fface, size, colR, colG, colB, content, tX, tY)
{

  // Add a new layer in the new document
  var artLayerRef = app.activeDocument.artLayers.add();

  // Specify that the layer is a text layer
  artLayerRef.kind = LayerKind.TEXT;

  //This section defines the color of the text
  textColor = new SolidColor();
  textColor.rgb.red = colR;
  textColor.rgb.green = colG;
  textColor.rgb.blue = colB;

  //Get a reference to the text item so that we can add the text and format it a bit
  textItemRef = artLayerRef.textItem
  textItemRef.font = fface;
  textItemRef.contents = content;
  textItemRef.color = textColor;
  textItemRef.size = size;
  //pixels from the left, pixels from the top
  textItemRef.position = new Array(tX, tY);
}

然后在完成之前添加 main() 函数,

create_text("Arial-BoldMT", 10, 0,0,0, "my text", docWidth - 10, docHeight -10);
activeDocument.activeLayer.textItem.justification = Justification.RIGHT;

该函数将在右上角附近放置 10 点文本。如果您想更改字体,您需要找到 postscript 字体名称。

Here's a function that will create text:

function create_text(fface, size, colR, colG, colB, content, tX, tY)
{

  // Add a new layer in the new document
  var artLayerRef = app.activeDocument.artLayers.add();

  // Specify that the layer is a text layer
  artLayerRef.kind = LayerKind.TEXT;

  //This section defines the color of the text
  textColor = new SolidColor();
  textColor.rgb.red = colR;
  textColor.rgb.green = colG;
  textColor.rgb.blue = colB;

  //Get a reference to the text item so that we can add the text and format it a bit
  textItemRef = artLayerRef.textItem
  textItemRef.font = fface;
  textItemRef.contents = content;
  textItemRef.color = textColor;
  textItemRef.size = size;
  //pixels from the left, pixels from the top
  textItemRef.position = new Array(tX, tY);
}

and then just before your finish the main() function just add

create_text("Arial-BoldMT", 10, 0,0,0, "my text", docWidth - 10, docHeight -10);
activeDocument.activeLayer.textItem.justification = Justification.RIGHT;

which will put 10 point text near the right hand corner. If you want to change the font you'll need to find the postscript font name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文