Advertisement


specific resize layer action


Question

Is there a way to resize one layer to the dimensions of another layer as an action. It seems you can only transform an object to percentages not pixel dims.

Thanks

2015/08/28
1
1
8/28/2015 10:44:00 PM

ACEkin's answer does not address the question. The question is about resizing as an action. When you record the action, Photoshop changes your pixel size input to a percentage, breaking the action and giving you an undesirable result when you use the action on a differently sized layer.

A workaround can be to save a script file, and have that script run in your action instead. However, the script I'm going to give will require you to edit it with the size you want.

This code is to transform the size by specifying a new width:

(function (){
    var startRulerUnits = app.preferences.rulerUnits;  
    app.preferences.rulerUnits = Units.PIXELS;  
    var bounds = activeDocument.activeLayer.bounds;  
    var width = bounds[2].value - bounds[0].value;
    var newSize = (100 / width) * 300;  
    activeDocument.activeLayer.resize(newSize, newSize, AnchorPosition.MIDDLECENTER);
    app.preferences.rulerUnits = startRulerUnits;  
})();

Save this code as a .jsx file with the name of your choosing, and put it in this folder:

PC: C:\Program Files\Adobe\Adobe Photoshop CS#\Presets\Scripts

MAC: /Applications/Adobe Photoshop CS5#/Presets/Scripts

Restart Photoshop, and you should be able to see your scripts name in the File -> Scripts menu. Now you can run it once on the layer by clicking on the name, or you can record yourself running it as part of an action.

As I said, you'll need to edit the script yourself to plug in the specific values you need. Currently it resizes the layer to a width of 300px, while keeping the height relative to the original aspect ratio. Simply change the 300 to whatever you need.

Here is a variation on the code to transform by height instead of width, again just substitute the 300 as required:

(function (){
    var startRulerUnits = app.preferences.rulerUnits;  
    app.preferences.rulerUnits = Units.PIXELS;  
    var bounds = activeDocument.activeLayer.bounds;  
    var height = bounds[3].value - bounds[1].value;
    var newSize = (100 / height) * 300;  
    activeDocument.activeLayer.resize(newSize, newSize, AnchorPosition.MIDDLECENTER);
    app.preferences.rulerUnits = startRulerUnits;  
})();

It is easy to alter the code so that a prompt asks you for the width or height, to save you having to edit the .jsx file. However, this isn't very useful for an action because it will pop up every single time. If you would like to do it anyway, just replace the 'var newSize' line with this:

var newHeight = prompt("Enter a new height in pixels.", 300);
var newSize = (100 / height) * newHeight;

Lastly just for completion, if you want to specify both height and width and ignore the original aspect ratio, you can use this code:

(function (){
    var startRulerUnits = app.preferences.rulerUnits;  
    app.preferences.rulerUnits = Units.PIXELS;  
    var bounds = activeDocument.activeLayer.bounds;  
    var width = bounds[2].value - bounds[0].value;
    var height = bounds[3].value - bounds[1].value;
    var newWidth = (100 / width) * 300;  
    var newHeight = (100 / height) * 300;  
    activeDocument.activeLayer.resize(newWidth, newHeight, AnchorPosition.MIDDLECENTER);
    app.preferences.rulerUnits = startRulerUnits;  
})();
2016/01/09
3
1/9/2016 4:05:00 PM