TransWikia.com

specific resize layer action

Graphic Design Asked by asburke on November 17, 2021

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

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 FilesAdobeAdobe Photoshop CS#PresetsScripts

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;  
})();

Answered by SQW on November 17, 2021

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

Answered by user45605 on November 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP