I have a script where I am trying to add a text layer onto an image and alter the font and size. The code work all by itself, but when added into the main script I can not get the font or size to work correctly. I hope is it something easy, but I can not figure it out.
This code works perfectly.
tell application "Adobe Photoshop CS2"
activate
make new document
set artLayerRef to make new art layer of current document with properties {kind:text layer}
set textItemRef to text object of artLayerRef
set font of textItemRef to "Helvetica"
set size of textItemRef to 25
set contents of contents of textItemRef to "Here's some text"
end tell
This does not work. The Text will change for some fonts, but I can not get the font size to change. Sometimes it gets bigger, but most of the time it is 75.
The part that is broken is at the bottom of this script, but if you see anything that is wrong I would appreciae that also.
property WatermarkFile : "Volumes/Shadrach/Imagine/Effects Watermark.tif"
set thefile to choose file {}
tell application "Adobe Photoshop CS2"
activate
tell application "Finder"
set theFileName to name of thefile
set theFileName to (text 1 thru ((length of theFileName) - 4) of theFileName)
end tell
open thefile as JPEG
set ImageDocument to current document
set background color to {class:RGB color, red:0, green:0, blue:0}
set fileWidth to width of ImageDocument
set fileHeight to height of ImageDocument
if fileWidth > fileHeight then
set ImageRatio to fileWidth / fileHeight
if ImageRatio > 1.62 then
set ImageResize to 700
else
set HeightRatio to fileHeight / 433
set ImageResize to fileWidth / HeightRatio
end if
else
set ImageResize to 433
end if
resize image ImageDocument width pixels ImageResize resample method bicubic
resize canvas ImageDocument width pixels 720 height pixels 540
tell current document
filter layer "BackGround" using unsharp mask with options {class:unsharp mask, amount:28, radius:1.9, threshold:0}
end tell
do action "Proofs" from "eMotion Actions"
flatten ImageDocument
set artLayerRef to make new art layer of current document with properties {kind:text layer}
set textItemRef to text object of artLayerRef
set font of textItemRef to "Helvetica"
set size of textItemRef to 25
set contents of contents of textItemRef to "Here's some text"
set position of textItemRef to {360, 500}
end tell
I am really frustrated with this because it seems like it should be so easy, but it is not allowing me to change the font or size consistently.
I don’t have APCS2, but it seems to me that your ‘telling’ is tangled
First, the Finder block should be right under the choose file.
Next, you set up a tell current document block when the current document is defined above as ImageDocument
Finally, although I’m not sure, if you’ve flattened the document can you then do your new stuff? Shouldn’t that be up where you’re setting size and ratio, etc.?
Haven’t had much time to look at this but at a quick glance think it should be more like this. Adam you were correct with what you said with the one exception Photoshop will allow you to flatten the layer stack at any point then continue to add new stuff above this but you can be forgiven for not knowing this without having the application.
property WatermarkFile : "Volumes/Shadrach/Imagine/Effects Watermark.tif"
set thefile to choose file {} without invisibles
tell application "Finder"
set theFileName to name of thefile
set theFileName to (text 1 thru ((length of theFileName) - 4) of theFileName)
end tell
--
tell application "Adobe Photoshop CS"
activate
set background color to {class:RGB color, red:0, green:0, blue:0}
set UserPrefs to properties of settings -- Store the users prefs
set ruler units of settings to pixel units -- Change the ruler units
open thefile -- No "as JPEG" required "open as" is a class with options ie EPS & PDF
set ImageDocument to current document
tell ImageDocument
set fileWidth to width
set fileHeight to height
if fileWidth > fileHeight then
set ImageRatio to fileWidth / fileHeight
if ImageRatio > 1.62 then
set ImageResize to 700
else
set HeightRatio to fileHeight / 433
set ImageResize to fileWidth / HeightRatio
end if
else
set ImageResize to 433
end if
resize image width ImageResize resample method bicubic
filter layer "BackGround" using unsharp mask with options ¬
{class:unsharp mask, amount:28, radius:1.9, threshold:0}
-- USM better before adding the black black edge
resize canvas width 720 height 540
do action "Proofs" from "eMotion Actions"
flatten
set artLayerRef to make new art layer at beginning with properties ¬
{kind:text layer}
set textItemRef to text object of artLayerRef
set font of textItemRef to "Helvetica" -- Must be postscript name
set size of textItemRef to 25
set contents of contents of textItemRef to "Here's some text"
set position of textItemRef to {360, 500}
end tell
set ruler units of settings to ruler units of UserPrefs -- Reset user ruler unit prefs
end tell
First let me say thank you for the quick response and the good pointers. Some of that bad coding was my frustration and putting stuff in there to see if it “will” work, but thank you for pointing out my mistakes. However, I am still not getting the font size to change in the bigger script.
For some reason the font is still sized at 75 or larger and I can not figure out why the difference or why I can not resize the font.
If you guys have ANY other options or suggestions I would love to hear them.
Unfortunately I don’t have CS2 yet so I can’t advise if this a bug issue with this release, I have seen posts about resizing issues but none have referred to the type object. The code works fine with CS1. You could try specifying the type units worded a different way see if that makes any difference. This also works in CS1.
tell application "Adobe Photoshop CS"
activate
set docRef to the current document
tell docRef
set myTextLayer to make new art layer in docRef ¬
with properties {kind:text layer, name:"Test Type"}
set properties of text object of myTextLayer to ¬
{font:"Optima-Bold", size:72, stroke color:{class:RGB color, red:255, green:0, blue:0}, position:{100, 300}, contents:"Here's some text."}
end tell
end tell