Copy link to clipboard
Copied
SuperMerlin you are awesome.
Allow me to make one more question.
The text is huge, is not respecting the measure or the font type set in the
script and is not in a new layer.
I've tried to change the value on the script but nothing changes. Can you
please help me with this last one?
This is the entire script now:
#target photoshop;
if(documents.length) app.activeDocument.suspendHistory('Add Border',
'main()');
function main(){
var startRulerUnits = preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc = activeDocument;
var fivePercent = (Math.min(doc.height,doc.width)/100) * 20;
var OffsetX = fivePercent;
var OffsetY = fivePercent/4;
var Black = new SolidColor();
Black.rgb.hexValue = '696969';
var White = new SolidColor();
White.rgb.hexValue = 'ffffff';
app.backgroundColor=White;
doc.flatten();
doc.resizeCanvas((doc.width + (fivePercent*2)), (doc.height +
(fivePercent*2)), AnchorPosition.MIDDLECENTER);
var newTextLayer = activeDocument.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
newTextLayer.textItem.kind = TextType.POINTTEXT
newTextLayer.textItem.color = Black;
newTextLayer.textItem.font = "Source Sans Pro Regular";
newTextLayer.textItem.size = 18;
newTextLayer.textItem.contents = "www.alessandro-vecchi.com";
var LB = doc.activeLayer.bounds;
var LHeight = Math.abs(LB[3].value) - Math.abs(LB[1].value);
var percentage = ((fivePercent/LHeight)*50);
doc.activeLayer.resize(percentage,percentage,AnchorPosition.MIDDLECENTER);
LB = doc.activeLayer.bounds;
var X = (activeDocument.width - (LB[2] - LB[0])) / 2;
var Y = (activeDocument.height - OffsetY) - LB[3];
doc.activeLayer.translate(X -LB[0],Y);
doc.flatten();
preferences.rulerUnits = startRulerUnits;
}
As usual, THANK YOU!
[ branched by moderator from Script for border in % ]
Aktualisiert
Super Awesome Merlin,
as i can't see my last question I will post again.
You made it and it works but the text doesn't follow the instructions of the script regarding size and font.
Also the text is not in a new layer.
I'm attaching an image so you can see. The canvas size is 4428 x 3263.
What I must do?
Thank you
Change the font to suit...
...#target photoshop;
if(documents.length) app.activeDocument.suspendHistory('Add Border', 'main()');
function main(){
var startRulerUnits = preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc = activeDocument;
var fivePercent = (Math.min(doc.height,doc.width)/100) * 20;
var OffsetX = fivePercent;
var OffsetY = fivePercent/4;
var Black = new SolidColor();
Black.rgb.hexValue = '696969';
var White = new SolidColor();
White.rgb.hexValue = 'ffffff';
app.backgroundCo
Copy link to clipboard
Copied
You have to use the postscript name of the font, I don't have the font on my machine that you want so please run this script to find yours...
#target photoshop
main();
function main(){
var Dlog =
"dialog{text:'Script Interface',bounds:[100,100,500,270],"+
"FontName:DropDownList{bounds:[30,40,370,60]},"+
"PostScriptName:EditText{bounds:[30,100,370,120]},"+
"statictext0:StaticText{bounds:[40,10,200,30] , text:'Font Name'},"+
"statictext1:StaticText{bounds:[40,70,141,87] , text:'Postscript Name'},"+
"button0:Button{bounds:[140,130,240,150] , text:'Ok' }}";
win = new Window(Dlog,"Use the Postscript Name in your script.");
try{
for (var i=0,len=app.fonts.length;i<len;i++) {
win.FontName.add ('item', app.fonts.name);
};
win.FontName.selection = 0 ;
win.PostScriptName.text = app.fonts[win.FontName.selection.index].postScriptName;
win.FontName.onChange = function() {
win.PostScriptName.text = app.fonts[win.FontName.selection.index].postScriptName;
};
win.center();
win.show();
}catch(e){alert(e + e.line); return;}
}
If you want the text layer, comment out or remove the line
doc.flatten();
Copy link to clipboard
Copied
Thank you for your answer but allow me to say that I didn't understand.
The font I'm willing to use is 'Source Sans Pro Regular'
The script you just sent me is to add to the original script?
Or is something to get the postscript name?
I that case I must make a new script with the code you just sent and insert in line 08 the 'Source Sans Pro Regular' instead of 'Font Name'?
Sorry once again but this is the first time i'm looking at codes.
Thank you
Copy link to clipboard
Copied
The above Script from Supermerlin is a separate Script to find out the postscript name of your font (e.g. Screenname: Arial Bold Italic = postscript name: Arial-BoldItalicMT)
The postscript name is the name you have to insert in your script...so if you want wo use the Font e.g. "Arial Bold Italic"
change:
newTextLayer.textItem.font = "Arial Bold Italic";
to:
newTextLayer.textItem.font = "Arial-BoldItalicMT";
Copy link to clipboard
Copied
Thank you for your support!!
I will be able to test just later today hope to make it happen!!
Copy link to clipboard
Copied
Hello,
I found the name of the font, is 'SourceSansPro-Regular'
I've replaced as you told but nothing has changed the script still doesn't insert the correct font nor the size of it.
Also the text is not in a new layer as it was at the beginning.
The entire script that I'm using now is this one:
#target photoshop;
if(documents.length) app.activeDocument.suspendHistory('Add Border', 'main()');
function main(){
var startRulerUnits = preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc = activeDocument;
var fivePercent = (Math.min(doc.height,doc.width)/100) * 20;
var OffsetX = fivePercent;
var OffsetY = fivePercent/4;
var Black = new SolidColor();
Black.rgb.hexValue = '696969';
var White = new SolidColor();
White.rgb.hexValue = 'ffffff';
app.backgroundColor=White;
doc.flatten();
doc.resizeCanvas((doc.width + (fivePercent*2)), (doc.height + (fivePercent*2)), AnchorPosition.MIDDLECENTER);
var newTextLayer = activeDocument.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
newTextLayer.textItem.kind = TextType.POINTTEXT
newTextLayer.textItem.color = Black;
newTextLayer.textItem.font = "SourceSansPro-Regular";
newTextLayer.textItem.size = 14;
newTextLayer.textItem.contents = "www.alessandro-vecchi.com";
var LB = doc.activeLayer.bounds;
var LHeight = Math.abs(LB[3].value) - Math.abs(LB[1].value);
var percentage = ((fivePercent/LHeight)*50);
doc.activeLayer.resize(percentage,percentage,AnchorPosition.MIDDLECENTER);
LB = doc.activeLayer.bounds;
var X = (activeDocument.width - (LB[2] - LB[0])) / 2;
var Y = (activeDocument.height - OffsetY) - LB[3];
doc.activeLayer.translate(X -LB[0],Y);
doc.flatten();
preferences.rulerUnits = startRulerUnits;
}
Where is the mistake?
Thank you for your help
Copy link to clipboard
Copied
I don't have that font so tried "SourceSansRoman-Black" and that worked?
also commented out the flatten so you will have a text layer.
#target photoshop;
if(documents.length) app.activeDocument.suspendHistory('Add Border', 'main()');
function main(){
var startRulerUnits = preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc = activeDocument;
var fivePercent = (Math.min(doc.height,doc.width)/100) * 20;
var OffsetX = fivePercent;
var OffsetY = fivePercent/4;
var Black = new SolidColor();
Black.rgb.hexValue = '696969';
var White = new SolidColor();
White.rgb.hexValue = 'ffffff';
app.backgroundColor=White;
doc.flatten();
doc.resizeCanvas((doc.width + (fivePercent*2)), (doc.height + (fivePercent*2)), AnchorPosition.MIDDLECENTER);
var newTextLayer = activeDocument.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
newTextLayer.textItem.kind = TextType.POINTTEXT
newTextLayer.textItem.color = Black;
newTextLayer.textItem.font =/* "SourceSansPro-Regular"; */"SourceSansRoman-Black";
newTextLayer.textItem.size = 14;
newTextLayer.textItem.contents = "www.alessandro-vecchi.com";
var LB = doc.activeLayer.bounds;
var LHeight = Math.abs(LB[3].value) - Math.abs(LB[1].value);
var percentage = ((fivePercent/LHeight)*50);
doc.activeLayer.resize(percentage,percentage,AnchorPosition.MIDDLECENTER);
LB = doc.activeLayer.bounds;
var X = (activeDocument.width - (LB[2] - LB[0])) / 2;
var Y = (activeDocument.height - OffsetY) - LB[3];
doc.activeLayer.translate(X -LB[0],Y);
//doc.flatten();
preferences.rulerUnits = startRulerUnits;
}
Copy link to clipboard
Copied
Hello Merlin,
Thanks for your answer.
So you are saying that:
For the layer I should code
doc.flatten(out)
Regarding the font I should code
newTextLayer.textItem.font =/* "SourceSansPro-Regular"; */"SourceSansRoman-Regular";
newTextLayer.textItem.size = 14;
Is this correct?
Copy link to clipboard
Copied
The last code posted should be what you want, except use your own font as required.
Copy link to clipboard
Copied
Yes.
Your code(s) (always) works as expected.
For the postScriptName use:
//newTextLayer.textItem.font = "SourceSansPro-Black"; // or
//newTextLayer.textItem.font = "SourceSansPro-Regular"; // or
newTextLayer.textItem.font = "SourceSansPro-Semibold";
Info:
Your own try
newTextLayer.textItem.font =/* "SourceSansPro-Regular"; */"SourceSansRoman-Black";
does use the font Source Sans Variable Black instead. (I know it's hard to find it without having the correct font)
----------------------------------------------
Alessandro Vecchi​ wrote:
… For the layer I should code
doc.flatten(out) …
No.
Like SuperMerlin already wrote in her code in post #6
comment out that line #34 (or remove that line completely)
//doc.flatten();
Have fun
Copy link to clipboard
Copied
SuperMerlin,
The last one I promise!!
it worked as you told! Perfect!
One thing thought!
The size of the font turned out 74 instead of 14.
Why?
Thank you so much for all your help man!
Copy link to clipboard
Copied
I also didn't understand why you wrote you code in that way.
The explanation for this behaviour is easy. Your code will always do what you say:
At first you set the font size in the code:
newTextLayer.textItem.size = 14;
But afterwards you scale/resize the textlayer (the active layer) :
doc.activeLayer.resize(percentage,percentage,AnchorPosition.MIDDLECENTER);
That's why the font size will change.
Copy link to clipboard
Copied
Hi,
I'm sorry but as I don't know nothing about coding I'm having a hard time.
Are you saying that I'm doing something wrong?
The positioning of the text is correct, in the absolute middle of the bottom area.
My concern is about the size that should be 14. I've tried to change to 14pt but returned me an error.
I know that I can change manually, I could do everything manually, but I want to create a script so I can batch process all the images at once as I have a ton of images to adjust.
Copy link to clipboard
Copied
Comment out the following line:
doc.activeLayer.resize(percentage,percentage,AnchorPosition.MIDDLECENTER);
(add two slashes // at the beginning of this line)
Then your text will have font size 14pt
Copy link to clipboard
Copied
Hello Pixxxel,
Thank you for your help!
Everything perfect besides the positioning that before was absolute center and now is center but at the bottom
I've added the // and the result was the one of the image attached.
There's a way to achieve the absolute center of the bottom portion (W and H)?
Thank you
Copy link to clipboard
Copied
Change the font to suit...
#target photoshop;
if(documents.length) app.activeDocument.suspendHistory('Add Border', 'main()');
function main(){
var startRulerUnits = preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc = activeDocument;
var fivePercent = (Math.min(doc.height,doc.width)/100) * 20;
var OffsetX = fivePercent;
var OffsetY = fivePercent/4;
var Black = new SolidColor();
Black.rgb.hexValue = '696969';
var White = new SolidColor();
White.rgb.hexValue = 'ffffff';
app.backgroundColor=White;
doc.flatten();
doc.resizeCanvas((doc.width + (fivePercent*2)), (doc.height + (fivePercent*2)), AnchorPosition.MIDDLECENTER);
var newTextLayer = activeDocument.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
newTextLayer.textItem.kind = TextType.POINTTEXT
newTextLayer.textItem.color = Black;
newTextLayer.textItem.font = "SourceSansRoman-Black";
newTextLayer.textItem.size = 18;
newTextLayer.textItem.contents = "www.alessandro-vecchi.com";
var LB = doc.activeLayer.bounds;
var LHeight = Math.abs(LB[3].value) - Math.abs(LB[1].value);
var X = (activeDocument.width - (LB[2] - LB[0])) / 2;
var Y = activeDocument.height - ((fivePercent/2) - (LHeight/2));
newTextLayer.textItem.position = Array(X,Y);
preferences.rulerUnits = startRulerUnits;
}
Copy link to clipboard
Copied
Thank you MagicMerlin for all your support!
The last script is perfect!!!
Thank you very much!!
Copy link to clipboard
Copied
Hi I came across this thread as it's also what I need , I have used the same script but with my own name inserted.
I've an IMac and I have created an action ok but it's coming up with an error (see pic)
can anyone help please?