'How to create a rectangle that is 100% of the width and 50% of the height of a photoshop document?
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();
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ghoul Fool |
