View Full Version : File names and Batching Actions
LightSite
06-15-2004, 09:52 AM
I'm using Photoshop and the Fit Image command to resize my images for a slide show program. The slide show software does not offer the ability to place the image number anywhere on the image. Is there someway to write an action in Photoshop that will grab the image name and place it where I designate on the image? Even stretching the canvas and filling with black and placing the name there would work. I'm not sure if this is possible or if I need to find an Apple Script to do this.
LightSite
06-16-2004, 12:26 PM
I've been asking in different forums about this subject and been told that it can be accomplished with a Java script. Anyone have enough experience with this to edit?
I've found three different scripts, I'd like to combine them into one "perfect" script.
jonbalza
06-16-2004, 01:01 PM
It sure can be done with Javascript... Post what you have so far, and some people might be willing to help out. Also, I think there was an action floating around here somewhere that would help you out.
Try a search for "watermark action" and see what comes up.
LightSite
06-16-2004, 01:40 PM
I think this one has more potential simply because it's set up to work with CMYK and RGB files. Is there anyway to eliminate the extension from the filename?
if ( documents.length > 0 )
{
/*
This script will add copyright information and filename on a text layer
*/
// set units to pixels
var originalRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
try
{
// add art layer
var docRef = activeDocument;
var artLayerRef = docRef.artLayers.add();
artLayerRef.kind = LayerKind.TEXT;
// ============= Personalize your values in the section below ============
// Copyright info
var myCopyrightText = "© Photographer Name 2004 - file: ";
// select opacity
artLayerRef.opacity = 100;
// select the text colour
var newColour = new SolidColor();
if (docRef.mode == DocumentMode.CMYK)
{
newColour.cmyk.cyan = 255;
newColour.cmyk.magenta = 255;
newColour.cmyk.yellow = 255;
newColour.cmyk.black = 0;
}
if (docRef.mode == DocumentMode.RGB)
{
newColour.rgb.red = 255;
newColour.rgb.green = 255;
newColour.rgb.blue = 255;
}
artLayerRef.textItem.color = newColour;
// select the font name
artLayerRef.textItem.font = "ArialMT";
// select the font size
artLayerRef.textItem.size = 10;
// select the text position - this can be an absolute value too, eg. (10,20)
artLayerRef.textItem.position = new Array(docRef.width / 2, docRef.height *0.05);
// select the text justification
artLayerRef.textItem.justification = Justification.CENTER;
// ============= Personalize your values in the section above ============
// add text item on the art layer
var textItemRef = artLayerRef.textItem;
// text contents is copyright info + filename
textItemRef.contents = myCopyrightText + docRef.name;
// dereference pointers
docRef = null;
artLayerRef = null;
textItemRef = null;
myCopyrightText = null;
newColour = null;
}
catch( e )
{
// received and error ... throw it back to the user
preferences.rulerUnits = originalRulerUnits;
throw e;
}
preferences.rulerUnits = originalRulerUnits;
}
else
{
alert( "Open a document first." );
}
jonbalza
06-16-2004, 02:22 PM
What about the second one is not working for you? It looks like that is exactly what you need it to be doing.
edit: Oh yeah, this code gets rid of the filename extension, provided you don't have a period (.) anywhere else in the title.
if ( documents.length > 0 )
{
/*
This script will add copyright information and filename on a text layer
*/
// set units to pixels
var originalRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
try
{
// add art layer
var docRef = activeDocument;
var artLayerRef = docRef.artLayers.add();
artLayerRef.kind = LayerKind.TEXT;
// ============= Personalize your values in the section below ============
// Copyright info
var myCopyrightText = "© Your name here 2004 - file: ";
// select opacity
artLayerRef.opacity = 100;
// select the text colour
var newColour = new SolidColor();
if (docRef.mode == DocumentMode.CMYK)
{
newColour.cmyk.cyan = 255;
newColour.cmyk.magenta = 255;
newColour.cmyk.yellow = 255;
newColour.cmyk.black = 0;
}
if (docRef.mode == DocumentMode.RGB)
{
newColour.rgb.red = 255;
newColour.rgb.green = 255;
newColour.rgb.blue = 255;
}
artLayerRef.textItem.color = newColour;
// select the font name
artLayerRef.textItem.font = "ArialMT";
// select the font size
artLayerRef.textItem.size = 10;
// select the text position - this can be an absolute value too, eg. (10,20)
artLayerRef.textItem.position = new Array(docRef.width / 2, docRef.height *0.05);
// select the text justification
artLayerRef.textItem.justification = Justification.CENTER;
// ============= Personalize your values in the section above ============
// add text item on the art layer
var textItemRef = artLayerRef.textItem;
// text contents is copyright info + filename
myCopyrightText = myCopyrightText + docRef.name;
var copyright_array = myCopyrightText.split(".");
textItemRef.contents = copyright_array[0];
// dereference pointers
docRef = null;
artLayerRef = null;
textItemRef = null;
myCopyrightText = null;
newColour = null;
}
catch( e )
{
// received and error ... throw it back to the user
preferences.rulerUnits = originalRulerUnits;
throw e;
}
preferences.rulerUnits = originalRulerUnits;
}
else
{
alert( "Open a document first." );
}
LightSite
06-16-2004, 02:50 PM
Sir Jon...thanks for being so quick. I tried the modification you suggested and when I run the script, the filename comes up and then is deleted. Not sure where the problem is coming from.
I have successfully been able to change the font, color and location. If I have to live with the extension I guess I will, but I'm sure someone with more knowledge than I will be able to figure it out quickly enough.
Also, is there any way to make the script run relative to document size? I was going to run this script as part of an action to batch out my full sized camera files to 800 pixels. If I run the same script on the full size image, the text is super tiny. Wondering if it could be set to scale relative to document size?
Working on the perfect script. Thanks for all the help, it's very much appreciated!
LightSite
06-16-2004, 02:57 PM
Sir Jon, I must apologize publicly...I errantly left out one line of your modified code and that was what prevented it from working properly. I have found the error and corrected it...Glad I don't write code for a living...that's quite impressive.
Thanks for fixing that! All that's left is my last question regarding placement relative to document size.
jonbalza
06-17-2004, 08:09 AM
Well, the reason your text might be super small or super big is because it is set to size it based on POINT size, which is not based off of the total dimensions of the image, but actually the DPI of the image. Which means if you have an 800x600px image at 300dpi, the text will be VERY small. But if it is 800x600 at 72dpi, the text will probably look like what you expect.
So to fix the problem, you want to make sure you resize the images to 72dpi AND 800x600, not just one or the other. (In other words, it's not in the script you need to fix that problem!)
Glad I could help, and I think I'm going to use that script at some point myself!
vBulletin® v3.6.8, Copyright ©2000-2009, Jelsoft Enterprises Ltd.