In this tutorial I will aim to show how to create this effect using scripts but will also show the corresponding steps in Photoshop, making it easy for you to understand how to alter your script to achieve different results.
although it may not work for older versions of Photoshop. There are a few advantages of using this program, mainly the debugger and the fact that you can run scripts straight from the program.
For most of the steps I will show what your image should look like after you have run the script. Throughout this tutorial I used this image
from stock.xchng, optionally you can save a small size version of this image for the purpose of testing your scripts as the script will run faster this way. The script works for any image of any size.
Open the editor you want to use, either ESTK or a regular text editor like notepad for Windows, don’t use a program like Microsoft Word for this. If your using ESTK then there should be a dropdown menu at the top left of the window, select Adobe Photoshop from this and this will link the program to Photoshop.
Now we will right a simple script to test we have the settings correct. Type the code shown below into your editor:
What this simple command will do is to bring up an alert box saying ‘Hello World’; we will use alert boxes throughout this tutorial in order to test parts of our script. By putting the quote marks in we are indicating that this is a string which is just a word.
Now run your script, If you are using a regular text editor like notepad then the easiest way to run your script is to save the file as ‘myscript.jsx’ then open Photoshop and go file>scripts>browse then select your script. If you are using ESTK then just hit the play button in the top right of the document window. Automatically you should see your alert box pop up. Before testing your scripts close any document that is open in Photoshop.
Delete the alert code you had in the editor as we were only using it to test the settings. There are two settings we want to apply every time we run our script, these are to tell Photoshop to use pixels as the default unit and not to display dialog boxes unless we tell it to. If we wanted to do this within Photoshop we would go edit>preferences>units & rulers and change the rulers value to pixels, obviously turning off dialog boxes is limited to the scripting only. The code for doing this is:
preferences.rulerUnits = Units.PIXELS; displayDialogs = DialogModes.NO
The first command is, simply telling Photoshop to access the rulerUnits within the preferences then change the units to pixels. You will notice that this is arranged in a hierarchical structure for example the rulerUnits is contained within the preferences, this is easy to visualise as Photoshop is arranged in exactly the same way.
The second command is basically telling Photoshop to change the value of displayDialogs to NO, if you wanted to have dialogs displayed while running the script then you would change the NO to YES.
Now we want to let the user select a file to open, for this we need to bring up an open dialog box, even though we turned dialogs off if we tell Photoshop to bring up a dialog it will do it. We then want to define a variable that references to this document then we want to duplicate the background layer. The code for doing this is:
open(File(openDialog())); var docRef_1 = activeDocument
The first command is made up of three parts, the open() command which will open the file within the brackets, next the File() command which fetches the file path within the brackets but instead of adding a path we added the openDialog() command. So this is displaying a dialog box where the user selects a file then it will get the file path and open that file, if you were wanting to open the same file each time you could swap the openDialog() with the file path and name .
In the next command what we are doing is setting up a variable using var then the variable name which can be anything but here I used docRef_1, if I was to open another document I would make a variable named docRef_2. We are then setting docRef_1 to be equal to the active document.
In the last command what we are doing is telling Photoshop to duplicate the background layer in docRef_1 which is the only document we have open anyway. You will notice again that this is similar to what you would do in Photoshop, as in you would select the document which contains the layer you want to duplicate then you would select the layer you want to duplicate then you would duplicate it.
Try running the full script now and you will end up with a background layer containing the image you chose and also a layer above that containing the same image.
To do this step in Photoshop you would simply go Ctrl+O then choose your file then right click on the background layer and select duplicate layer.