Manipulate an Image with Scripting

Manipulate an Image with Scripting
Manipulate an Image with Scripting
open(File(openDialog())); var docRef_1 = activeDocument
docRef_1.backgroundLayer.duplicate();

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.

clip_image002

Step 4:

Now I will show you how to define colors using hexadecimal codes, colors can be defined in other ways like by RGB values as we will see later. Here we will define a white color and a black color then set black as the foreground and white as the background. There is other ways of doing this but for the purpose of this tutorial I will show you this way. The code for this step is:

var white = new SolidColor(); white.rgb["hexValue"] = "ffffff" var black = new SolidColor(); black.rgb["hexValue"] = "000000" foregroundColor = black; backgroundColor = white;

You will notice here that the first two lines are roughly the same as the second and third; what we are doing here is setting up a variable which can be named anything but here we use the color it will contain as the variable name. We are then saying that this variable is equal to new SolidColor() which is a function for creating a new color. The next line is setting the hexadecimal value for this color to whatever the color should be so for white this is "ffffff", what we are ultimately saying here is that white is the color white and black is the color black.

Pages: 1 2 3 4 5 6 7 8 9

Create Dot Grid Art in 1 Click
Sponsored

Turn any photo into a dot grid artwork with these Photoshop actions. You'll get great results with dots that change size. They get larger in brighter areas and smaller in darker areas. Free download available.

One comment on “Manipulate an Image with Scripting”

Leave a Reply

Your email address will not be published. Required fields are marked *

cross