🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.photoshop.scripting
Article #1800

Re: Auto pasting of a filename onto a layer in PS7/CS

#1800
From: c_watts
Date: Sat, 10 Jul 2004 13:20
83 lines
3167 bytes
This will annotate an image with the filename. It will pick the best text size based on the size of the image. There is a ReRes thing that happens because, as I recall, there is a bug in the way that JS/PS picks font sizes even when they are specified in points. Anyway, I wrote this a while ago, and I don't remember exactly.

This is shamelessly hacked together from Adobe examples, but it works!

chris

function ReRes(NewResolution)	{

	var strtRulerUnits = preferences.rulerUnits;
	var strtTypeUnits = preferences.typeUnits;
	preferences.rulerUnits = Units.PIXELS;
	preferences.typeUnits = TypeUnits.PIXELS;

	var docRef = activeDocument;
	var docName = docRef.name;
	var MyImageHeight = docRef.height;
	var MyImageWidth = docRef.width;

	docRef.resizeImage(undefined, undefined , NewResolution,ResampleMethod.NONE)

}

//MakeMask and add the file name

function PickBestTextSize()	{

	var strtRulerUnits = preferences.rulerUnits;
	var strtTypeUnits = preferences.typeUnits;
	preferences.rulerUnits = Units.PIXELS;
	preferences.typeUnits = TypeUnits.PIXELS;

	var docRef = activeDocument;
	var docName = docRef.name;
	var MyImageHeight = docRef.height;
	var MyImageWidth = docRef.width;
	var CalcTextSize= MyImageHeight/23.5;

	return CalcTextSize;
}

function AddFileName(xlocation,ylocation, myFont,myFontSize, rColor, gColor, bColor)

	{
//Annotates the frame with a file name in the desired spot

var strtRulerUnits = preferences.rulerUnits;
var strtTypeUnits = preferences.typeUnits;
preferences.rulerUnits = Units.PIXELS;
preferences.typeUnits = TypeUnits. PIXELS;

//var docRef = documents.add(7, 5, 72);

var docRef = activeDocument;
var docName = docRef.name

// suppress all dialogs
displayDialogs = DialogModes.NO;

var textColor = new SolidColor;
textColor.rgb.red = rColor;
textColor.rgb.green = gColor;
textColor.rgb.blue = bColor;

var newTextLayer = docRef.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
newTextLayer.textItem.contents = docName;
newTextLayer.textItem.position = Array(xlocation,ylocation);
newTextLayer.textItem.size = myFontSize;
newTextLayer.textItem.color = textColor;
newTextLayer.textItem.font = myFont;

preferences.rulerUnits = strtRulerUnits;
preferences.typeUnits = strtTypeUnits;
docRef = null;
textColor = null;
newTextLayer = null;

activeDocument.activeLayer.merge()

}

ReRes(72)
AddFileName(20,PickBestTextSize()*1.5, "Lucida Grande" , PickBestTextSize() , 220, 220, 220)
Technical Details
Message-ID: <3bb4f458.0@webx.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!feed.news.schlund.de!schlund.de!newsfeed01.sul.t-online.de!t-online.de!webx
References: <3bb4f458.-1@webx.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f5839,1a13a1daed981d92
X-Google-Attributes: gidf5839,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: c_watts@adobeforums.com
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!feed.news.schlund.de!schlund.de!newsfeed01.sul.t-online.de!t-online.de!webx
Newsgroups: adobe.photoshop.scripting
Subject: Re: Auto pasting of a filename onto a layer in PS7/CS
Message-ID: <3bb4f458.0@webx.la2eafNXanI>
Date: Sat, 10 Jul 2004 06:20:28 -0700
References: <3bb4f458.-1@webx.la2eafNXanI>
Lines: 90
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit