USING VARIABLES IN PHOTOSHOP WITH EXTERNAL DATA SOURCE
Using variables in Photoshop is akin to using layer comps. The major different is that when you use variables you are retrieving the data from a data source instead of just turning layers on and off. Photoshop can use layer names as variable placeholders. Then, these placeholders can be "filled" with data from a data source which could be a simple text file. This is akin to using a mail merge program or even server-side scripting like Coldfusion, ASP(.NET), PHP or JSP. Like Layer comps, this can save you a ton of time if you need to create a multitude of images that have basically the same layout (template) but need different text and graphic on each image (i.e., business cards, trading cards, web ads, web banners, posters, etc.).
CREATE OR PREPARE IMAGES
Images need to be created or prepared that will be used to replace the placeholders.
- Create or prepare an image for each placeholder in the data set (explained next) and place them in the same folder as the Photoshop file you will be creating.
NOTE: It is best that the images be of the same size.
CREATE A DATA SOURCE
Like most database driven applications, it is best to define the database (or data source) BEFORE you build an application. Likewise, we will first start with a data source so we will know in advance how to name the variables using the first row in our data source. You now need to bind or connect the (layer) variable names with the names in the data source. This is akin to what is done when binding data to a database using server-side technologies (i.e., ColdFusion, etc.). There are two ways to create a data source: external or internal. In this tutorial we will use an external data source.
To create a data source OUTSIDE of Photoshop, follow the procedure below:
- Create a comma delimited or tab-delimited text file (i.e., mydata.txt) to represent the data.
CAUTION: Be careful not to include commas inside the data (i.e., He loves football, baseball, basketball and hockey) because the data will be exported and comma separated values (*cvs) which will render the file useless.
It is so much easier to use an Excel worksheet or a Access database and output its data as a comma delimited file (*.csv).
NOTE: You can also create data-driven layouts in Adobe InDesign.
EXAMPLE OF DATA HERE:
||Ann enjoys bike riding and reading.
||Bob enjoys spending time with family and friends.
||Personal interests include mountain climbing and snow skiing.
||Loves working with communities groups to help enhance her community.
||Love reading and writing for local organizations.
||Personal interests include playing basketball and football.
||Personal interests include modeling and swimming.
||Loves doing outdoors activities with friends.
||Loves spending time with his wife and kids doing outdoors activities.
||Love to help other less fortunate than herself.
||Loves to sing and dance.
||Enjoys going to the movies.
NOTE: Path names to images can be absolute or relative to the folder where the images are located (i.e., images).
CREATE LAYOUT TEMPLATE
Create a layout template using static and dynamic text and graphics layers as placeholders.
IMPORTANT: Because the layer names will be treated as variables later, you must follow the following naming convention for layers that will be dynamic: Variable names must begin with a letter, underscore, or colon and cannot contain spaces or special characters (except for periods, hyphens, underscores, and colons).
Create Background Layer
- Create a new file with the desired dimension you need for your project. (The Photoshop default size will be used to demonstrate this example)
- If necessary, create a background layer or import a background image. (A gradient background is used in this example -- See below)
Create Dynamic Text Placeholder(s) via Text tool
- Create a text layer as a DYNAMIC text placeholders and adjust the font size and style to your liking and then give the layer the SAME name as in the data set header name you just created. (In this case, employee_full_name is used for the first text field.).
NOTE: Remember, by naming the layer the same as the header, it will be treated as a variable for the text placeholder later.
TIP: Use the longest text in your data source as the length for each text placeholder so that the text does not get cut off. It is best NOT to simply click on the canvas to create a text object. Instead "drag out" a text area that is almost the width of the canvas and "center" the text inside of the text object using the align center tool. See example below:
- Repeat the previous steps to create additional dynamic text holder(s) as needed. (Here, four more text placeholders were added.)
NOTE: The text placeholders in this case are left justified instead of centered and the notes font size has been reduced.
TIP: Turn on the grid to assist you in aligning text placeholders if needed.
Create Dynamic Graphic Placeholder(s) via Rectangle Tool or a Real Image
- Similiar to the text placeholders, use the Rectangle Tool (U) with the Fill pixels option selected in the Option bar to "draw" a graphic placeholder that represents the typically size of the image that they will be replaced later and then give the layer the SAME name as the data set header name you created earlier.
TIP: You could also use an actual image as a placeholder; however, since it will be replaced with data from the data set later, it is not necessary. This is a better approach because it helps you visualize your project and you don't have to find out the image size if they are set already. In fact, in this case, this is just what was done.
TIP: Just like the text field, you can also "style" the image placeholder with layer styles as was done in the screen shot below.
- Repeat the previous steps to create additional dynamic graphics holder(s) as needed, if needed.
Create STATIC text fields or STATIC graphics
- Create STATIC text fields via Text tool or create / import STATIC graphics that will be the same on all images. (In this example, only static text fields are added.)
TIP: You can duplicate the existing dynamic text fields and then edit and move them into place so that you don't have to type them in. If you do, don't forget to rename the layers to something more descriptive (i.e., department_name to department_name static text so that you don't get them confused with the dynamic text fields when you make them variables.
NOTE: Once you are completed adding dynamic text/graphic and static text/graphics, you have create a template that will be used in the next section.
DEFINE DATA VARIABLES
The dynamic layers names in the Layers Panel need to be "matched" to the header names in the data source for both the text and graphics layers.
Choose Image > Variables > Define... and then make the following changes.
Create Text Data Set
- Ensure that Define (CTRL+1) is selected and not Data Set (CTRL+2) in the first drop-down menu.
- Select a Text Layer from the Layer: drop down menu. (In this case, employee_full_name was selected)
- Select the Text Replacement checkbox and then give the variable the SAME name as the name in the Layer: drop-down box you selected earlier.
NOTE: If you wanted to create an OPTIONAL TEXT variable, select the Visibility checkbox and enter or select a variable. A good use for this option would be if you were selling some products and you want to have a SOLD text appear across items that have been already sold. You could create a TRUE and FALSE variables in your data source to determine when to show the text..
NOTE: An asterisk ( * ) will appear next to the layer name in the Layers text field.
NOTE: If you choose an existing variable to link to a link icon will appear next to the Name text field.
- Repeat this process for the other text layers. DO NOT select the static layers. (In this case, four more layers were defined (department_name, st art_date, extension, and notes)
You can use the left and right navigation arrows on the right side of the Layer text field to move between layers or select a Layer from the Layer: drop-down menu.
Create Graphic Data Set
- Select a Graphic Layer from the Layer: drop down menu. (In this case, photo)
- Ensure that the Pixel Replacement checkbox is selected and then give the variable the SAME name as the Layer: drop-down box you selected earlier.
NOTE: If you wanted to create an OPTIONAL IMAGE variable, select the Visibility checkbox and enter or select a variable. A good use for this option would be if you were selling some products and you want to have a SOLD image appear across items that have been already sold. You could create a TRUE and FALSE variables in your data source to determine when to show the image.
NOTE: While you can define variable for any custom background layer (i.e., Background copy), you cannot define variables for the default Background layer.
- Set the Method (In our example, the Fit method was selected. However, because all of our images are of the same size, we could have also used the As Is option).
TIP: Select a method and then hover over the Method text field to see a visual and text on how that method works:
NOTE: You can also select Clip To Bounding Box to clip areas of the image that do not fit in the bounding box. This option is available only when the Fill or As Is replacement method is selected except for the Conform method.
You can also click on one of the Alignment alignment point (square) except for the Conform method to resized image to the center or to an edge.
- Repeat this process for any other graphic layer (In this case, there is none.)
You can use the navigation arrows to move between layers.
NOTE: You can also set the visibility of both a text or graphic layer.
NOTE: To rename a variable, enter a new name in the Name text box. To remove a variable, simply deselect it.
IMPORT DATA SET
Create a data set from the text file as the data that will fill the placeholders with real values.
- While still in the Variables dialog box, click the Import.... button.
- In the Import Data Set dialog box:
- Click the Select File... button and then select the text data file you created earlier and then click the Load button followed by the OK button.
- Select Automatic from the Encoding: drop-down menu.
- Select Use First Column For Data Set Names checkbox.
- Click OK to close Import Data Set dialog box.
NOTE: You will SEE the Variables dialog box get populated with variable data. Now the data variables are bound together and given their corresponding values.
You can then select the Preview checkbox and then click the right and left arrows near the Data Set: text field to preview result on the canvas.
NOTE: You aan also preview the data set by selecting Image . Apply Data Set adn select a data set that you would like to preview. If you click on the Apply button, you will change the current layer.
- Click OK to close the Variables dialog box and to return to Photoshop.
EXPORT DATA SETS
You can now export the the result as individual Photoshop psd files.
Choose File > Export > Data Sets as Files.... In the dialog box, select your destination folder and file naming options and then click OK to export each data set "record" as an individual Photoshop psd file.
NOTE: Each file is a layered psd file and can be open and edited separately.
To flatten these images, select File > Scripts > Image Processor... or select them in Bridge and choose Tools > Photoshop > Image Processor.
You can also use Bridge to create a Web Photo Gallery (WPG) by selecting the images in Bridge and choosing the Output option.
(Bonus) Transforming Graphics using Layer Comps
Normally if you try to transform (i.e, rotate) an image on a layer, when it is replaced by the real image it will be straight again. To resolve this problem, create a script to rotate that particular layer and then preform a Batch process on those images
Create a simply Action to:
- Select a layer (in this case, the photo).
NOTE: Since the photo layer is common to all images, the Batch process will work correctly.
- Rotate the image
- Save the Action
- Run a Batch process using the Action you just created to transform (i..e., rotate) the image in all psd files.