Photoshop / image manipulation

Hello there,
I’m new to posting here today, but have been using this board as a resource for about a year.

I’m currently trying to produce ‘handwritten’ sentences, from individual .tiffs of single letters on a transparent background.
I have downloaded the Adobe applescript document for PShop and there seems to be no way of pasting at a position, or moving a layer within a document.

Essentially, what I would like to do is this:

  • Input a short sentence from a text box.
  • Convert this string to a series of filenames corresponding to the individual letters I have prepared.
  • open the letters in sequence as new layers in photoshop
  • spread them a fixed distance apart, at the same ‘y location’.

Once I have this document, I can fiddle with the layers a little to make it look more natural.

Anyone know a way of either controlling the ‘paste position’, or of moving layers?
Failing that is there any more suitable software than photoshop for this?

Many thanks.
Miller.

Miller, this should get you part of the way. This should work with either no document open or on the current doc (if it was created by the script on previous run). Moving things about in layers is best done @ 72dpi for easier maths. Each time the script is run you should get a new “word” layer set and your characters added to this from their files. At present I have only the time to align to vertical & horizontal centers. I don’t have time just at the minute to come up with a routine that is going to calculate the spacing/alignment for you. Should get you started though.

property Temp_H : 1200
property Temp_W : 3600
property Temp_Res : 72
--
set Letters_Folder to choose folder with prompt "Where is your folder of letters" without invisibles
--
set The_Dialog to display dialog "Enter your character string" default answer ""
set The_Characters to characters of (text returned of The_Dialog)
--
tell application "Adobe Photoshop CS2"
	set display dialogs to never
	set User_Rulers to ruler units of settings
	set ruler units of settings to pixel units
	activate
	if exists current document then
		set Temp_Doc to the current document
	else
		set Temp_Doc to make new document at beginning with properties ¬
			{mode:CMYK, height:Temp_H, width:Temp_W, resolution:Temp_Res, initial fill:transparent}
	end if
	tell Temp_Doc
		set Word_Layer to make new layer set at end with properties ¬
			{name:((The_Characters) as text)}
	end tell
end tell
--
repeat with i from 1 to count of The_Characters
	tell application "Finder"
		set The_Letter to file ((item i of The_Characters) & ".tif") of Letters_Folder as alias
	end tell
	tell application "Adobe Photoshop CS2"
		open The_Letter
		set Letter_Doc to the current document
		tell Letter_Doc
			set Letter_W to width
			set Letter_H to height
			duplicate layer 1 to beginning of Temp_Doc
			close without saving
		end tell
		tell Temp_Doc
			translate layer 1 delta y (Temp_H - Letter_H) / 2
			translate layer 1 delta x (Temp_W - Letter_W) / 2
			move layer 1 to end of Word_Layer
		end tell
	end tell
end repeat
--
tell application "Adobe Photoshop CS2"
	set ruler units of settings to User_Rulers
end tell

Wow, very cool!

letterspacing the text shouldn’t be too hard - the script just needs to keep a running count of the distance in pixels from the left margin and offset the x coordinate of each placed letter by that much. In other words, get the width of each letter as it is imported and use that to offset the next one.

Let’s make it handle spaces while we’re at it …

This would work well for photographed, scanned, or hand-drawn text (I’m thinking of old decorative Victorian alphabets or neon sign letters). If the goal is to typeset your handwriting, I recommend Fontifier http://www.fontifier.com/ - they have a simple web-based app that will turn your handwriting into a font for the extremely reasonable price of $9 !!

With basic letter spacing added. Im sure there’s a better way to do this math but it functions at least.

property Temp_H : 1200
property Temp_W : 3600
property Temp_Res : 72
--
set Letters_Folder to choose folder with prompt "Where is your folder of letters" without invisibles
--
set The_Dialog to display dialog "Enter your character string" default answer ""
set The_Characters to characters of (text returned of The_Dialog)
set Char_Count to count of The_Characters
--
tell application "Adobe Photoshop CS2"
	set display dialogs to never
	set User_Rulers to ruler units of settings
	set ruler units of settings to pixel units
	activate
	if exists current document then
		set Temp_Doc to the current document
	else
		set Temp_Doc to make new document at beginning with properties ¬
			{mode:CMYK, height:Temp_H, width:Temp_W, resolution:Temp_Res, initial fill:transparent}
	end if
	tell Temp_Doc
		set Word_Layer to make new layer set at end with properties ¬
			{name:((The_Characters) as text)}
	end tell
end tell
--
repeat with i from 1 to Char_Count
	tell application "Finder"
		set The_Letter to file ((item i of The_Characters) & ".tif") of Letters_Folder as alias
	end tell
	tell application "Adobe Photoshop CS2"
		open The_Letter
		set Letter_Doc to the current document
		tell Letter_Doc
			set Letter_W to width
			set Letter_H to height
			duplicate layer 1 to beginning of Temp_Doc
			close without saving
		end tell
		tell Temp_Doc
			translate layer 1 delta y (Temp_H - Letter_H) / 2
			translate layer 1 delta x (Temp_W - Letter_W) / 2
			move layer 1 to end of Word_Layer
		end tell
	end tell
end repeat
--
tell application "Adobe Photoshop CS2"
	tell Temp_Doc
		set Spacing to 20 -- Letter spacing + or -
		set Split to Char_Count div 2
		if Char_Count mod 2 = 0 then
			repeat with j from Split to 1 by -1
				tell layer (Split + 1 - j) of Word_Layer
					translate delta x -(((j * (Letter_W + Spacing)) - ((Letter_W + Spacing) / 2)))
				end tell
			end repeat
			repeat with k from 1 to Split
				tell layer (Split + k) of Word_Layer
					translate delta x ((k * (Letter_W + Spacing)) - ((Letter_W + Spacing) / 2))
				end tell
			end repeat
		else
			repeat with j from Split to 1 by -1
				tell layer (Split + 1 - j) of Word_Layer
					translate delta x -(j * (Letter_W + Spacing))
				end tell
			end repeat
			repeat with k from 1 to Split
				tell layer (Split + k + 1) of Word_Layer
					translate delta x k * (Letter_W + Spacing)
				end tell
			end repeat
		end if
	end tell
	set ruler units of settings to User_Rulers
end tell

Wow, this is great. I stopped checking back after a while and got things working myself by just pasting and using GUI scripting to ‘nudge’ the layer ten pixels at a time (shift, right arrow) from within a loop.
Modifying my loop using this code will speed things up hugely.

Many thanks!
Miller.