Manipulate an Image with Scripting

Manipulate an Image with Scripting
Manipulate an Image with Scripting

The last two lines set the foreground color to black and the background color to white, and are fairly easy to look at and understand straight away. In Photoshop the equivalent action for doing this would just be to hit D to reset the colors.

Try now, setting the foreground color and background color to a random color manually then running the full script which should give you the same result as we got in step 3 but now the foreground and background colors will be set properly.


Step 5:

Now we are going to fill the background layer white using the white color we set up in the last step. For this we first need to make a selection around the whole document then fill that selection. The code for this is:

docRef_1.selection.selectAll(); docRef_1.selection.fill(white); docRef_1.selection.deselect();

The first line creates a selection using the selectAll() function, for any command that can be used on different documents we have to tell Photoshop which document we are working on even though we only have one open in this case.

The second line is telling Photoshop to fill this selection in with the white color. Sometimes it is confusing as it wouldn't be stupid to think that something like docRef_1.selction.fill = white would do what we are trying to do, but this isn't a real command and this is where ESTK comes in useful as it will point out the correct use of something like the fill command just by typing in fill.

The third line is fairly self explanatory, it will deselect the selection, exactly the same as hitting Ctrl+D in Photoshop.

Again test the script and you should end up with a white background layer and the image in the layer above. In Photoshop, all this could have been done using Ctrl+A then Shift+F5 to select all then fill the selection.


Step 6:

In the next two steps we will use a script to find the average color in the photograph; we will then use this information to decide how to edit the image. This part of the script could have lots of other uses for example you could use a similar script to create a color chart based on the colors that make up the image. In this step we will first duplicate the image layer then we will apply an average blur filter which will find the average color then fill the layer with that color. The code for doing this is:

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 to Drake Cancel reply

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

cross