Here you\'ll find tutorials that don\'t belong to either of the above categories. This is the place for the most extraordinary materials.  Home Photoshop Miscellaneous Canvas Size

Canvas Size


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.

var oldRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

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.

var oldRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

if (documents.length > 0) {

}


3. If an image exist, the script will run the resizeCanvas() method.

var oldRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

if (documents.length > 0) {
resizeCanvas();
}


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():

var oldRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

if (documents.length > 0) {
activeDocument.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.

var oldRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

if (documents.length > 0) {
activeDocument.resizeCanvas(1000,700);
}


6. You may also anchor the position by typing in AnchorPosition() with one of the following values inside the parenthesis ( ):

image 1

var oldRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

if (documents.length > 0) {
activeDocument.resizeCanvas(1000,700,AnchorPosition.BOTTOMRIGHT);
}


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.


Author's URL: FotoFects
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

Advance your current skills or acquire new skills in Photoshop by creating projects using our step-by-step tutorials. More Tutorials: Most Popular Materials | Fresh Materials | TutorialKit New Photoshop Tutorials

Add comments to "Canvas Size"

Only registered users can write comment

No comments yet...