• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Script for border in %

Participant ,
May 01, 2019 May 01, 2019

Copy link to clipboard

Copied

Hello,

I want to create a script to add a white border with my website as signature to an entire batch of images with different sizes.

I've researched here and I found a script but when I've tried to customize to my needs returns me error on the 7 line.

As i never used a script nor know how to code, could anyone assist me with this issue please?

I also would like the text to be centralized in "height" and "width" on the bottom white bar.

I've already sweated a lot to customize this simple text to what I would like to achieve.

Thank you very much!

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 = (doc.height/100) * 20;

var OffsetX = twentyPercent;

var OffsetY = twentyPercent/4;

var White = new SolidColor();

White.rgb.hexValue = 'ffffff';

var White = new SolidColor();

White.rgb.hexValue = 'ffffff';

app.backgroundColor=White;

doc.flatten();

app.activeDocument.resizeCanvas((doc.width + (twentyPercent*2)), (doc.height + (twentyPercent*2)), AnchorPosition.MIDDLECENTER);

var newTextLayer = activeDocument.artLayers.add(); 

newTextLayer.kind = LayerKind.TEXT; 

newTextLayer.textItem.kind = TextType.POINTTEXT

newTextLayer.textItem.color = White; 

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 = ((twentyPercent/LHeight)*50);

doc.activeLayer.resize(percentage,percentage,AnchorPosition.MIDDLECENTER);

LB = doc.activeLayer.bounds; 

var X = (activeDocument.width - twentyPercent) - LB[2].value;

var Y = (activeDocument.height - OffsetY) - LB[3];

activeDocument.activeLayer.translate(X,Y);

doc.flatten();

preferences.rulerUnits = startRulerUnits;

}

TOPICS
Actions and scripting

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , May 01, 2019 May 01, 2019

if you want to chage to 20 percent change:

var fivePercent = (Math.min(doc.height,doc.width)/100) * 5

to

var fivePercent = (Math.min(doc.height,doc.width)/100) * 20

Votes

Translate

Translate
Adobe
Guide ,
May 01, 2019 May 01, 2019

Copy link to clipboard

Copied

I think the original code was here:-

Creating a uniform border as a percentage of image size. How?

Does this do what you want?

#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) * 5;

var OffsetX = fivePercent;

var OffsetY = fivePercent/4;

var Black = new SolidColor();

Black.rgb.hexValue = '000000';

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 = "Georgia";

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;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 01, 2019 May 01, 2019

Copy link to clipboard

Copied

Yes!

That’s the original code.

What I’ve tried in my effort of customizing is to change the percentage from 5 to 20 and the border color from black to white, besides the text at the bottom.

In the code I’ve posted there’s some error because photoshop was unable to run the script.

Anyway thank you for your time replying to my post!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 01, 2019 May 01, 2019

Copy link to clipboard

Copied

if you want to chage to 20 percent change:

var fivePercent = (Math.min(doc.height,doc.width)/100) * 5

to

var fivePercent = (Math.min(doc.height,doc.width)/100) * 20

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 01, 2019 May 01, 2019

Copy link to clipboard

Copied

Thank you!

In the line

var OffsetX = fivePercent;

I must change to twentyPercent ?

Once again thank you for your help!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 01, 2019 May 01, 2019

Copy link to clipboard

Copied

No, only the first change is required.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 01, 2019 May 01, 2019

Copy link to clipboard

Copied

You indeed are super Merlin!!!!!!!

It works!!!!!!

BUT

There's one thing.

Regarding the text i want to place, my url, I've changed in the code from

Black to '696969' and returned an error

A Text layer was created but it's empty.

The text code i think is this one

(fivePercent*2)), AnchorPosition.MIDDLECENTER);

var newTextLayer = activeDocument.artLayers.add();

newTextLayer.kind = LayerKind.TEXT;

newTextLayer.textItem.kind = TextType.POINTTEXT

newTextLayer.textItem.color = '696969';

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);

How can I make the text with this color appear and get placed in the center

in height and width?

THANK YOU!!!!!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 01, 2019 May 01, 2019

Copy link to clipboard

Copied

leave,

newTextLayer.textItem.color = Black;

change

Black.rgb.hexValue = '696969';

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 01, 2019 May 01, 2019

Copy link to clipboard

Copied

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

Screen Shot 2019-05-02 at 06.48.35.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 01, 2019 May 01, 2019

Copy link to clipboard

Copied

LATEST

This topic is solved.

Your last question was branched to a new thread: [ Branched ] Additional text changes in [JS] Script for border in %

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines