If you are new to scripting for Photoshop, please view our Photoshop Scripting Basics tutorial for an introduction to Photoshop scripting and a few exercises about basic JavaScript.
1. Save the current ruler units preference and change
it to one you would like to work with.
For a better understanding of the above code, please read the Setting the Ruler and Type Units tutorial. |
|
| |
|
2. Now we need to check if a document is opened so
that the script only runs when it is. To do this, we can simply check the image size. If the image
has a length, then it must exist.
|
|
| |
|
3. If an image exist, the script will run the resizeCanvas()
method.
|
|
| |
|
4. The resizeCanvas() method need to know what it will
resize. We want the current active document to be resized so we'll type in activeDocument in front
of resizeCanvas():
|
|
| |
|
5. Finally, we can add the paramaters. Type inside
the resizeCanvas parenthesis ( ) the width and height with a comma between them. Because I set
the ruler units to "PIXELS", the numbers I enter will be in pixels.
|
|
| |
|
6. You may also anchor the position by typing in AnchorPosition()
with one of the following values inside the parenthesis ( ):
|
|
| |
|
| 7. Save the script and run it in Photoshop. If you do not have a document already opened, it'll do nothing. The script should canvas the image size to 1000x700 pixels if you have your document opened. | |





More Photoshop: