Hey, in this Awesome Photoshop tutorial, i’m gonna show you how to write a script that creates text blocks using the photo-letters you put into a folder. Throughout this tutorial you’ll download some images of signs and crop and resize them to create the letters. Then you’ll write the script asking for a text input, then tiling the letter images accordingly. This one is an advanced tutorial and i believe might come in handy for people who want to learn about scripting and love typography. Have fun.
Here is what we’ll get
Before we start lets see the final image we’ll create through out this tutorial. You can download the archive containing the sample glyps and the script here.
In this tutorial we’ll first create 300×300 photo letters from photographs. Then we’ll create a script. Our script will ask the user to input some text and a number of columns. Using this information it will calculate the number of rows necessary and then tile 300x300pixel images of letters in the pre-calculated grid and give us a final image like in the below.
Create the Folder
OK. Let’s start by creating a folder for our script file and glyph files. If you are a Windowser, open up the Drive "C:" and create a new folder named "PSA-TypoTiler". If you’re using a Mac, then create a new folder on the Desktop and name it "PSA-TypoTiler". Into this folder, we’re gonna put all the images of letters and our script file as well.
Prepare the Glyphs
The first thing to do is to prepare the letters, or let’s just call them glyphs. You can find images of letters by searching Flicker for some signs, or you can grab your camera, head to a big city full of signs and shoot your own letters. Here i give you links of some photos we’ll use in this tutorial to create letters A, E, M, O, S, W and the Star. We’ll replace spaces with a star. Open up the first image in Photoshop. Now we have to decide how wide and high our glyps will be. For this tutorial we’ll use 300×300 pixels glyps and it is important for all glyps to have the exact same dimensions. Get the Crop Tool, set Width and Height to 300 pixels, make a rectangular selection surrounding letter A and double click inside the selection to crop. After croping it Photoshop will scale it to 300×300 pixels. Then save the image as a JPEG file into the PSA-TypoTiler folder you have just created at the first step and name it "a.JPG".
Start Writing the Script
OK. Let’s start writing the script. Start the Adobe ExtendedScript Toolkit application. Enter the code below. The first line says that the units in Pixels, and when we say e.g. "blockheight=300", it means 300 pixels. Other lines defines variables assingning them a value except the first one, it only declares a variable, we’ll give it a value later. "blockwidth" and "blockheight" variables are set to 300(pixels) this is the dimension of our glyphs. "columns" is going to be set by the user later, but the default value is set to 3. Finally, the "horizontal" and the "vertical" variables is going to be used to count the columns and rows.
Create the Dialog Box
Now write or paste the below code. Here we create a new dialog named "dlg" and set it’s title to "PsAwesome-TypoTiler-v1.0". Then we define a Panel which is 340 pixels wide and 60 pixels high and add a text box saying "Width" and a Scrollbar that has a minimum value of 1, maximum value of 16 and default value of 3. We’ll use that scroll bar to get the number of columns. In the next line we add a text box to show the value of the scrollbar, then make it uneditable by the user and pass the value of the scrollbar to that text box. Finally we have a function which will be triggered when the scrollbar is changed. That function rounds the floating number of the scrollbar, passes it to the text box and set the pre-defined variable "columns" to that value as well. Until now we have created a Dialog Box and some panels on it, at the end the code we wrote so far will look like as in the below image. To see it you do two things. The first is to set the Target Application to Photoshop. Then add "dlg.center();" and "dlg.show();" lines at the bottom of the code to center the dialog and make it visible, and remember it should always be at the bottom. Now you can click the Play button to see what hou have done by now.
Add another Panel
Continue writing the code. Here in this piece of code, we add another Panel named "textPnl" to the "dlg" window. Then we add a multiline editable text box for user to input text.
Add the Buttons
Using the below code we add a Group to our "dlg" Dialog Box to hold the two buttons, "GO" and "Cancel".
Create the Function
Now here the important part begins. Start by creating a Function to be triggered when user clicks the "GO" button. The first thing the Function does is to close the dialog box. Then it creates a variable named "textt" and passes the user written text to that variable..
Analyze the Text and Create Document
The code below checks if the number of letters in the user text divided by the number of columns give a decimal or not. If it does, it means we will need another row at the bottom so it adds 1 to number of letters divided by number of columns. If the result doesn’t have a decimal it means that it is something like 6/3 or 8/4 so number of letters divided by number of columns gives us the number of rows. We’ll use that information to create a new document. For now we know how many columns and rows we’ll need, and we can calculate the dimensions of our document. Let’s define two variables; one of them is "wd", the width of the document which equals to columns x blockwith, the width of our individual glyphs. The other variable is for the height of the document which equals to rows*blockheight, the width of our individual glyphs. The last line of the below code creates a new document wd x hg pixels at a resolution of 300, named "PSA TypoTiler".
Open the Glyph and Copy
After creating the new document, in the first line of the below code we start a loop which repeat for each character of the input text. Then we create a "fname" variable and assign each letter of the text to it and add ".JPG". If the input text is "PEACE" for example, the loop will run 5 times and fname will be "p.JPG", "e.JPG", "a.JPG", "c.JPG" and "e.JPG". If the current character is a space, then fname will be "space.JPG". With in the loop we create a variable called "glyphToOpen" and define the path and the filename to open, and open it with "open(glyphToOpen)" command. Assume that the text is "PEACE", and the loop is running for the second time, "fname" will be "e.JPG" and the "glyphToOpen" will be "C:/PSA-TypoTiler/e.JPG". Then we get the layer named "Background", select it all, copy the selection and close the document. After the document is closed the active document is now "PSA TypoTiler".
If you’re using Mac then you should define the path like this: