1

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

2 Answers 2

3

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;  
})();
1
  • your script is just what I've been looking for, and I have got it working. However, is it possible for the script to only run when the layer that needs to be resized is, for example, greater than 300px? Commented Apr 15, 2016 at 17:34
2

I am not sure of the specifics of your need, but in the Free Transform toolbar you will see two input fields where you can enter the width and the height. You can enter these values either as percentages or in pixels. I am adding a screen capture to show you that, yes you can indeed enter pixel values. I am addressing the question, the rest is up to you.

enter image description here

2
  • You can actually use inches also, type "1in"; "1px"; "1%" etc
    – Yorik
    Commented Oct 28, 2015 at 15:06
  • @user45605 Yes, but when you "record" such a resize action in a Photoshop Action, it will record the resize in percentages, not in inches (or cm). So when you playback the recorded action with an image that has a different size, the result will not be what you expect, as the resized layer will not be resized to the same "inch" size that you specified in the action when you recorded it. This is a really annoying bug. For example, it makes it impossible to create an Action that will rezise a layer to match the image width, regardless of the image width (in inches).
    – loupiote
    Commented Jul 22, 2020 at 3:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.