Join Julieanne Kost to discover how to use variables to automatically replace text and photos in a template to generate data-driven graphics.
- [Instructor] Although variables have been in Photoshop for many years, only a small number of people know of its immense power for tasks such as automating event photography or creating web banners or producing graphics. Let's say, for example, that you need to produce 500 different web banners or 200 different business cards based on a template. In the past, you had to manually populate the template with the text, the people's names, and the different photographs but fortunately, variables can automate this entire process.
So here we can see that I have a template. And the template has four different layers. And if we use the Eye Icon to toggle the visibility, we can see that on the left I need to replace the left side with a big photo. On the right side we have a small photo. Then I have a graphic that's a color bar. I want to replace that and also some text. In order to replace these using variables, let's switch to Bridge so I can show you all of the necessary elements need to be in the same document as the template and as the spreadsheet that we're going to use in order to marry all of these different graphics and elements and text with the template.
And in fact, let's take a look at this Excel spreadsheet for a moment. You can see that there's four different columns. There's a text column, a color bar, small photo, and big photo. And then underneath that is the name, or in this case the text that I want to replace in image two, three, or four. So we can think of these as being data sets. So for example, the data set of two is I want to replace the text with Joshua Tree. That's the name of the color bar. That's the small photo and that's the big photo.
What's really important with these column names is that there's no spaces in the column names. So your variable names must begin with a letter. They cannot contain spaces or special characters except you can add a period, a hyphen, an underscore, or a colon in the variable name. And the variable name that we define in Photoshop is going to match exactly with the column name. So that means even upper and lower case matter. So I try to be really simple when I name my columns so that the columns here are going to match the variable names and just to make it easy, I try to match the layer name as well.
Okay, the only problem is I have this spreadsheet but unfortunately, Photoshop doesn't want an Excel spreadsheet. What it wants is a tab-delimited text file. So from the File Menu, I'll choose Save As. I want to save this locally to the same folder. So I'll navigate to the Desktop and then to the Exercise Files, Chapter Five, and then Variables. For file format, I'll choose tab-delimited text and select Save.
I'll click Continue and when we return to bridge, we can see that Parks.txt. If I double-click to open that, we can see that it's tab-delimited, meaning that there's a tab between text and color bar, so between the column names as well as the individual pieces of information that we're going to use as our data set. Of course we didn't have to start in Excel. You could just create a tab-delimited text file and Photoshop can use that in variables.
All right, let's move to Photoshop and we need to define our variables. Under the Image Menu, I'll choose variables and then Define. You'll notice we can see each one of our layers and when I select a layer, I can choose a Variable Type, either Visibility or Pixel Replacement. So for the big photo, I want a Pixel Replacement and then I need to name that variable. And remember this name needs to be exactly the same as the column name so I'll call it Big Photo.
Remember there can't be any spaces. Then I'll move to Small Photo. Again, Pixel Replacement and call it Small Photo. One more time with color bar. That's a Pixel Replacement and I'll call it Color Bar. Now it just so happens that all of my graphics match the size that they need to be but if you have images that are different shapes and sizes and resolution, you might need to pick a different method to fit the image.
So I can Fit it. I could Fill it. I could place the photo As Is, or the graphic As Is, or I can tell it to Conform. And with many of these like the Fill, I can then choose an Alignment. So it could align it in the upper left or the center. For now, because they are all the correct size, I'll choose Fit and I have one last variable and that's Text that's going to be a Text Replacement and we'll just call it Text. Okay. Once I've defined all of the variables, I can quickly move to Data Sets, although I just want to point out if you click OK, you can also access the Data Sets under the Image Menu under Variables, returning to Data Sets.
I need to import my Data Sets so I'll click Import. I'll select a file so I'll navigate to the Desktop and then to the Exercise Files, Chapter Five and Variables. I'll select that Parks text file, leave the encoding to Automatic, leave Use first Column For Data Set Names blank and choose to Replace the Existing Data Sets just in case I need to load this again. I'll click OK and toggle on the Preview.
Let's move this out of the way and we can see that Data Set One is replacing the large photo, the small photo, the color bar, and the text. If I move to the next Data Set, Photoshop will automatically generate the graphic using the next set of images and text and if I move again to Data Set Three, it will swap out all of that. Now, when I click OK, it looks as if nothing has happened and that's because I need to export these files.
Under File > Export and then Data Sets as Files. I'll select a folder to export to. In this case, I'll use the Chapter Five 03 variables. I'll make a new folder called Processed Graphics. Click Create. Choose that folder. I want to export all of the Data Sets and I'm just going to let it rename with the defaults but you have a number of different options that you can choose from here if you want to change the name.
I want to add the file extension in lower case and I'll make this compatible for Windows as well as Unix. Click OK. Photoshop will export those. If we look in Bridge at the processed graphics, there are the three processed graphics. So while for three graphics it might take more time to set up the variables, you can imagine if you had 300 graphics or 3000 graphics how much time variables can save you in Photoshop.
- Quickly saving images as different file types
- Creating single and multi-step actions
- Saving and loading actions
- Inserting stops, menu items, and conditionals
- Tips for working with layers
- Using the Batch command
- Creating droplets
- Automatically creating graphics from layers using generators
- Working with variables and scripts