LampShade
LampShade

Reputation: 2775

Add flat amount to canvas size

I want to have some automated process (either action or script) that will copy selection(assumes something has already been selected), place in new canvas, increase canvas size by exactly 10 pixels in height & width, then save it to the desktop.

I'm currently using an action and it works correctly with the exception of the 10 pixels part. I can do something like 10% by using the percentage adjustment in the canvas size menu, but I can't figure out how to do exactly 10 pixels. During the recording, if I just increase the canvas size by 10 pixels it'll record that exact amount (say it was 100x100, it records that I resized canvas to 110x100). So when I play that action on a selection that's of size 50x50 it resizes it to 110x110.... So the problem is that the action records the literal value of the canvas resize and not the add 10 pixels part...

Any ideas here?

Upvotes: 0

Views: 100

Answers (1)

Anna Forrest
Anna Forrest

Reputation: 1741

This can be scripted as well, but if you've already got an action set up, try modifying your action to do the following:

  • paste the selection into new document larger than you expect to ever require
  • expand the selection by 10 px
  • crop the document to the selection
  • save

Or, to script it you can tweak the following sample. It assumes you have already copied your image to the clipboard:

#target photoshop
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;

var doc = app.documents.add('1000px');
var lyr = doc.artLayers.add();
doc.activeLayer = lyr;
doc.paste ();
var bnds = lyr.bounds;

var unitsToAdd = new UnitValue(10, 'px');

bnds[0] = bnds[0] - unitsToAdd;
bnds[1] = bnds[1] - unitsToAdd;
bnds[2] = bnds[2] + unitsToAdd;
bnds[3] = bnds[3] + unitsToAdd;

doc.crop(bnds) ;

doc.saveAs(new File('/c/temp/temp.psd'));

Upvotes: 2

Related Questions