hi all,
I use a text layer to put text on image, but when use different size of images the text is different
and must be set size of the font text everytime.
For example 800x600 image and text arial size 18, 1024x768 image and text font size 20.
There is a mode to calculate imagine size and set the percentual of text and not size for the same result?
Thanks in advance.
text layer
text layer
Here is an example of text that is 50% of the width of the document, and set 30 pixels from the bottom....
Code: Select all#target photoshop
main();
function main(){
if(!documents.length) return;
var Percent = 50; //Percent of width of document
var TextInfo = "Your Text Here";
var Black = new SolidColor();
Black.rgb.hexValue = '000000';
var newTextLayer = activeDocument.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
newTextLayer.textItem.kind = TextType.POINTTEXT;
newTextLayer.textItem.color = Black;
newTextLayer.textItem.font = "Georgia";
newTextLayer.textItem.size = 10;
newTextLayer.textItem.contents = TextInfo;
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var myDoc = activeDocument;
var LB = myDoc.activeLayer.bounds;
var docWidth = myDoc.width;
var LWidth = Math.abs(LB[2].value) - Math.abs(LB[0].value);
var percentageWidth = ((docWidth/LWidth)*Percent);
myDoc.activeLayer.resize(percentageWidth,percentageWidth,AnchorPosition.MIDDLECENTER);
align('AdCH'); align('AdBt');
activeDocument.activeLayer.translate(0,-30);
app.preferences.rulerUnits = startRulerUnits;
}
function align(method) {
activeDocument.selection.selectAll();
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putEnumerated( charIDToTypeID( "Usng" ), charIDToTypeID( "ADSt" ), charIDToTypeID( method ) );
try{
executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );
}catch(e){}
activeDocument.selection.deselect();
};
Code: Select all#target photoshop
main();
function main(){
if(!documents.length) return;
var Percent = 50; //Percent of width of document
var TextInfo = "Your Text Here";
var Black = new SolidColor();
Black.rgb.hexValue = '000000';
var newTextLayer = activeDocument.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
newTextLayer.textItem.kind = TextType.POINTTEXT;
newTextLayer.textItem.color = Black;
newTextLayer.textItem.font = "Georgia";
newTextLayer.textItem.size = 10;
newTextLayer.textItem.contents = TextInfo;
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var myDoc = activeDocument;
var LB = myDoc.activeLayer.bounds;
var docWidth = myDoc.width;
var LWidth = Math.abs(LB[2].value) - Math.abs(LB[0].value);
var percentageWidth = ((docWidth/LWidth)*Percent);
myDoc.activeLayer.resize(percentageWidth,percentageWidth,AnchorPosition.MIDDLECENTER);
align('AdCH'); align('AdBt');
activeDocument.activeLayer.translate(0,-30);
app.preferences.rulerUnits = startRulerUnits;
}
function align(method) {
activeDocument.selection.selectAll();
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putEnumerated( charIDToTypeID( "Usng" ), charIDToTypeID( "ADSt" ), charIDToTypeID( method ) );
try{
executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );
}catch(e){}
activeDocument.selection.deselect();
};
text layer
Thanks a lot Paul work 100%.
So I can modify only the percentage and put the same size (10) for all fonts ?
So I can modify only the percentage and put the same size (10) for all fonts ?
text layer
I have another question.
Now use classic textitem position to set the text on the picture.
For example:
TextLayer.textItem.justification = Justification.LEFT;
TextLayer.textItem.position = Array(variable, variable);
I sow on your example tha use:
activeDocument.activeLayer.translate(0,-30);
Is better my code or your code?
Thanks a lot again
Now use classic textitem position to set the text on the picture.
For example:
TextLayer.textItem.justification = Justification.LEFT;
TextLayer.textItem.position = Array(variable, variable);
I sow on your example tha use:
activeDocument.activeLayer.translate(0,-30);
Is better my code or your code?
Thanks a lot again
text layer
You can use any font and the font size does not matter.
As for positioning the text, so long as it gets placed where you want it, that's good enough.
As for positioning the text, so long as it gets placed where you want it, that's good enough.
text layer
Hi Paul,
I try to use this code to put the text in vertical manually on the left top of the image but don't work good.
align('AdLf'); align('AdTp');
activeDocument.activeLayer.translate(offsetX, offsetY);
activeDocument.activeLayer.rotate(-90);
The text is out of the image on top.
For example if offsetx is 0 and offsety in orizontal is perfect, but in vertical is not correct.
There is a mode to put the text exaclty manually on vertical position?
Thanks a lot again
Paul
I try to use this code to put the text in vertical manually on the left top of the image but don't work good.
align('AdLf'); align('AdTp');
activeDocument.activeLayer.translate(offsetX, offsetY);
activeDocument.activeLayer.rotate(-90);
The text is out of the image on top.
For example if offsetx is 0 and offsety in orizontal is perfect, but in vertical is not correct.
There is a mode to put the text exaclty manually on vertical position?
Thanks a lot again
Paul
text layer
Thanks a lot works ok 100%.
Sorry, but why when load a array on the dropdownlist there is also the first item empty?
This is the sample:
Code: Select allvar prcV = new Array();
for (var i = 1; i <101; i++) {
prcV = i + " %";
}
var dlg = new Window("dialog", " test ", [100,100,350,350]);
dlg.sez.prDl = dlg.sez.add("dropdownlist", [50,20,150,41], prcV);
I have regular 1-2-3 etc but the first item on dropdownlist is empty and is not correct.
Sorry, but why when load a array on the dropdownlist there is also the first item empty?
This is the sample:
Code: Select allvar prcV = new Array();
for (var i = 1; i <101; i++) {
prcV = i + " %";
}
var dlg = new Window("dialog", " test ", [100,100,350,350]);
dlg.sez.prDl = dlg.sez.add("dropdownlist", [50,20,150,41], prcV);
I have regular 1-2-3 etc but the first item on dropdownlist is empty and is not correct.
text layer
You need to set the selection to the item you want to show, in this case the first item....
Code: Select allvar prcV = new Array();
for (var i = 1; i <101; i++) {
prcV = i + " %";
}
var dlg = new Window("dialog", " test ", [100,100,350,350]);
dlg.prDl = dlg.add("dropdownlist", [50,20,150,41], prcV);
dlg.prDl.selection=1;
dlg.show();
Code: Select allvar prcV = new Array();
for (var i = 1; i <101; i++) {
prcV = i + " %";
}
var dlg = new Window("dialog", " test ", [100,100,350,350]);
dlg.prDl = dlg.add("dropdownlist", [50,20,150,41], prcV);
dlg.prDl.selection=1;
dlg.show();