🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.photoshop.scripting
Article #503

Text background fill

#503
From: Juraj_Hammer
Date: Fri, 02 Jan 2009 14:57
88 lines
3183 bytes
Hi,
I do have this nice script to add a file name into the picture. I would like to add a rectangle behind the text but I don't know how.

Could you please help me.

/ this script is a variation of the script addTimeStamp.js that is installed with PS7
//Copyright 2002-2003. Adobe Systems, Incorporated. All rights reserved.
//All amendments Copyright Brian Price 2004 (brian@secalis.com)

//Check if a document is open
if ( documents.length > 0 )
{
var originalRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PERCENT;

try
{
var docRef = activeDocument;

// Create a text layer at the front

var myLayerRef = docRef.artLayers.add();
myLayerRef.kind = LayerKind.TEXT;
myLayerRef.name = "Filename";
var myTextRef = myLayerRef.textItem;

//Set your parameters below this line

//If you wish to show the file extension, change the n to y in the line below, if not use n.
var ShowExtension = "n";
// Insert any text to appear before the filename, such as your name and copyright info between the quotes.
//If you do not want extra text, delete between the quotes (but leave the quotes in).
var TextBefore = "";

// Insert any text to appear after the filename between the quotes.
//If you do not want extra text, delete between the quotes (but leave the quotes in).
var TextAfter = "";

// Set font size in Points
myTextRef.size = 60;

//Set font - use GetFontName.js to get exact name
myTextRef.font = "ArialNarrow";

//Set text colour in RGB values
var newColor = new SolidColor();
newColor.rgb.red = 0;
newColor.rgb.green = 255;
newColor.rgb.blue = 200;
myTextRef.color = newColor;

// Set the position of the text - percentages from left first, then from top.
myTextRef.position = new Array( 2, 98);

// Set the Blend Mode of the Text Layer. The name must be in CAPITALS - ie change NORMAL to DIFFERENCE.
myLayerRef.blendMode = BlendMode.NORMAL;

// select opacity in percentage
myLayerRef.opacity = 100;

// The following code strips the extension and writes tha text layer. fname = file name only

di=(docRef.name).indexOf(".");
fname = (docRef.name).substr(0, di);
//use extension if set
if ( ShowExtension == "y" )
{
   fname = docRef.name
   }

myTextRef.contents = TextBefore + " " + fname + " " + TextAfter;

}
catch( e )
{
// An error occurred. Restore ruler units, then propagate the error back
// to the user
preferences.rulerUnits = originalRulerUnits;
throw e;
}

// Everything went Ok. Restore ruler units
preferences.rulerUnits = originalRulerUnits;
}
else
{
alert( "You must have a document open to add the filename!" );
}
Technical Details
Message-ID: <59b76899.-1@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!newshub.sdsu.edu!webcrossing

Show Full Headers
Complete Article Headers
X-Google-Thread: f5839,316cbaf55885981b,start
X-Google-Attributes: gidf5839,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: Juraj_Hammer@adobeforums.com
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!newshub.sdsu.edu!webcrossing
Newsgroups: adobe.photoshop.scripting
Subject: Text background fill
Message-ID: <59b76899.-1@webcrossing.la2eafNXanI>
Date: Fri, 2 Jan 2009 06:57:57 -0800
Lines: 99
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit