• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Is there a way to resize the height of multiple images at once without setting a specific width?

Community Beginner ,
May 08, 2018 May 08, 2018

Copy link to clipboard

Copied

I have multiple images with different dimensions.  Is there a way to resize the height of multiple images at once without setting a specific width?  I tried using the default action in photoshop (default > actions > commands > image size) but it requires I resize all images to have the same width.

Screen Shot 2018-05-08 at 6.24.02 PM.png

TOPICS
Actions and scripting

Views

6.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

LEGEND , May 11, 2018 May 11, 2018

Copy it to notepad. Save as "Steady Height with Proportional Width.jsx" (incl. double quotes) into 'Presets / Scripts' of your Photoshop folder. Then (re)launch Ps and you will find this script in 'File / Scripts' menu. You may bind some shortcut to it, so any time you want to use this script you will just press some key(s) (in some cases you didn't specified it may not work):

preferences.rulerUnits = Units.PIXELS

function sTT(v) {return stringIDToTypeID(v)}

(ref = new ActionReference()).putEnumera

...

Votes

Translate

Translate
LEGEND , May 12, 2018 May 12, 2018

I wrote it in CS6 EXTENDED, but now tried in 19.1.3 version and it works too however you are right as I mistaken height with width. Now I corrected order, so layers won't be based on width, but height length. Additionally I added 'locked' layers case. So each time script meets them, they will be bypassed. Processing selected layers only version I will do a little later. Change:

resize(s = 600 / ((b = bounds)[2] - b[0]) * 100, s)

to

if (!positionLocked) resize(s = 600 / ((b = bounds)[3] - b[1]) * 10

...

Votes

Translate

Translate
Adobe
Adobe Employee ,
May 08, 2018 May 08, 2018

Copy link to clipboard

Copied

Hi Jaylal,

 

Could you please try going to File > Scripts > Image processor and try that option and let us know how it goes?

 

Check out this article for steps: How to Batch Resize in Photoshop: A Step-by-Step Guide (2021)

 

 

Regards,

Sahil

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

Hey! Thanks for the reply.  Unfortunately, I was asked me to define a width as well.

Screen Shot 2018-05-09 at 1.33.00 PM.png

Also, I think I should clarify what I am trying to do.  I want to resize all images to have the same height while retaining each individual image dimensions (the PSD file is a collage and the width of the images I want to resize do not matter).  Is there a function that will allow me to resize all 4 images at once to give them a height of 600px while retaining their original dimensions (so the width would automatically resize based on the height of the image)?  Is it possible to do this in the original PSD file (without needing to alter the images in an outside folder)?

For example, my desired height is 600 px:

  • image 1 is 400 px x 200 px > resized to 1200 px x 600 px
  • image 2 is 525 px x 300 px > resized to 1050 px x 600 px
  • image 3 is 600 px x 375 px > resized to 960 px x 600 px
  • image 4 is 1000 px x 500 px > resized to 1200 px x 600 px

Screen Shot 2018-05-09 at 2.02.45 PM.png

End Result (all images have a height of 600 px):

Screen Shot 2018-05-09 at 2.14.29 PM.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

For example, my desired height is 600 px:

  • image 1 is 400 px x 200 px > resized to 1200 px x 600 px
  • image 2 is 525 px x 300 px > resized to 1050 px x 600 px
  • image 3 is 600 px x 375 px > resized to 960 px x 600 px
  • image 4 is 1000 px x 500 px > resized to 1200 px x 600 px

In all cases, you are upsizing the layers… Which may lead to poor quality results. You appear to have smart objects so the current pixel dimensions may not be that small and you may have an excess of original pixels than the 600px height.

I believe that you will need a script that works at a unit of measure for px rather than %.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

This script will resize to 600px height on a single active/targeted layer.

Further code would be needed to loop through selected layers or all layers… but further error checks for locked or invisible layers may also be needed. A complex conditional action could be used to run this script, however scripting would be more elegant.

// https://forums.adobe.com/thread/988084

// Line 13 = Change Current Layer Height to 600px

#target photoshop 

function main(){ 

if(!documents.length) return; 

var startRulerUnits = app.preferences.rulerUnits; 

app.preferences.rulerUnits = Units.PIXELS; 

var doc = activeDocument; 

var res= doc.resolution; 

var LB = activeDocument.activeLayer.bounds; 

var Height= LB[3].value - LB[1].value; 

var onePix = 100/Height; 

var newSize = onePix * 600; 

doc.activeLayer.resize( newSize , newSize, AnchorPosition.MIDDLECENTER);  

app.preferences.rulerUnits = startRulerUnits; 

main();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 10, 2018 May 10, 2018

Copy link to clipboard

Copied

Stephen, excellent, you post made me ponder, we need building blocks of code, like a library, with the recursivity, hidden layer check, etc. Even better would be suite-wide automation similar to Automator/workflow that non coders could use, to perform those tasks...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

Agreed, coding cheats for non-coders would be great!

 

OK, I found a relatively simple method:

 

1. Record the script that I posted in reply #6 into an action.

2. Use the following script to run the action over the selected layers:

 

Run Action.jsx

 

Prepression: Downloading and Installing Adobe Scripts

 

Run-Actions.png

 

 

// https://raw.githubusercontent.com/Paul-Riggott/PS-Scripts/master/Run%20Action.jsx 

#target photoshop

app.bringToFront();

 

main();

function main(){

if(!documents.length){

  alert("You need to have at least one document open!");

  return;

}

var win = new Window( 'dialog', 'RA' );

g = win.graphics;

var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]);

g.backgroundColor = myBrush;

win.orientation='stack';

win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});

win.g1 = win.p1.add('group');

win.g1.orientation = "row";

win.title = win.g1.add('statictext',undefined,'Run Action(s)');

win.title.alignment="fill";

var g = win.title.graphics;

g.font = ScriptUI.newFont("Georgia","BOLDITALIC",22);

win.p1.p1= win.p1.add("panel", undefined, undefined, {borderStyle:"black"});

win.p1.p1.preferredSize=[300,2];

win.g3 =win.p1.add('group');

win.g3.orientation = "row";

win.g3.alignment='fill';

win.g3.spacing=10;

win.g3.cb1 = win.g3.add('checkbox',undefined,'Create Snapshop');

win.g5 =win.p1.add('group');

win.g5.orientation = "row";

win.g5.alignment='fill';

win.g5.spacing=10;

win.g5.cb1 = win.g5.add('checkbox',undefined,'Run Action(s) On All Layers');

win.g5.cb1.value=true;

win.g6 =win.p1.add('group');

win.g6.orientation = "row";

win.g6.alignment='fill';

win.g6.spacing=10;

win.g6.cb1 = win.g6.add('checkbox',undefined,'Run Action(s) On Selected Layer(s)');

if(activeDocument.layers.length < 2){

  win.g6.cb1.enabled=false;

  }

var selectedLayers= getSelectedLayersIdx();

if(selectedLayers.length <1) win.g6.cb1.enabled=false;

 

win.g5.cb1.onClick=function(){

  if(win.g5.cb1.value){

  win.g6.cb1.value=false;

  }else{

  win.g6.cb1.value=true;

  if(selectedLayers.length >1) win.g6.cb1.enabled=true;

  }

}

win.g6.cb1.onClick=function(){

  if(win.g6.cb1.value){

  win.g5.cb1.value=false;

  }else{

  win.g5.cb1.value=true;

  }

}

win.g5.cb1.onClick();

win.p1.p2= win.p1.add("panel", undefined, undefined, {borderStyle:"black"});

win.p1.p2.preferredSize=[300,2];

win.g10 =win.p1.add('group');

win.g10.orientation = "row";

win.g10.alignment='fill';

win.g10.spacing=10;

win.g10.dd1 = win.g10.add('dropdownlist');

win.g10.dd2 = win.g10.add('dropdownlist');

win.g15 =win.p1.add('group');

win.g15.orientation = "row";

win.g15.alignment='fill';

win.g15.spacing=10;

win.g15.st1 = win.g15.add('statictext',undefined,'Selected Actions');

win.g15.et1 = win.g15.add('edittext',undefined,'0');

win.g15.et1.preferredSize=[40,20];

win.g15.et1.enabled=false;

win.g15.bu1 = win.g15.add('button',undefined,'Add Action');

win.g15.bu2 = win.g15.add('button',undefined,'Remove Action');

win.p1.p3= win.p1.add("panel", undefined, undefined, {borderStyle:"black"});

win.p1.p3.preferredSize=[300,2];

win.g20 =win.p1.add('group');

win.g20.orientation = "row";

win.g20.alignment='center';

win.g20.spacing=10;

win.g20.bu1 = win.g20.add('button',undefined,'Process');

win.g20.bu1.preferredSize=[170,35];

win.g20.bu2 = win.g20.add('button',undefined,'Cancel');

win.g20.bu2.preferredSize=[170,35];

 

var actionSets = new Array();

actionSets = getActionSets();

for (var i=0,len=actionSets.length;i<len;i++) {

win.g10.dd1.add ('item', "" + actionSets); 

};

win.g10.dd1.selection=0;

 

var actions = new Array();

actions = getActions(actionSets[0]);

for (var i=0,len=actions.length;i<len;i++) {

win.g10.dd2.add ('item', "" + actions); 

};

win.g10.dd2.selection=0;

 

win.g10.dd1.onChange = function() {

win.g10.dd2.removeAll();

actions = getActions(actionSets[parseInt(this.selection)]);

for (var i=0,len=actions.length;i<len;i++) {

win.g10.dd2.add ('item', "" + actions); 

}

win.g10.dd2.selection=0;

};

actionArray=[];

win.g15.bu1.onClick = function() {

actionArray.push([[win.g10.dd2.selection.text],[win.g10.dd1.selection.text]]);

win.g15.et1.text = actionArray.length;

}

win.g15.bu2.onClick = function() {

actionArray.pop();

win.g15.et1.text = actionArray.length;

}

win.g20.bu1.onClick=function(){

if(actionArray.length ==0) actionArray.push([[win.g10.dd2.selection.text],[win.g10.dd1.selection.text]]);

win.close(1);

if(win.g5.cb1.value){

  selectAllLayers();

  selectedLayers= getSelectedLayersIdx();

  }

if(win.g3.cb1.value) snapShot();

for(var a in selectedLayers){

  makeActiveByIndex(Number(selectedLayers));

  if(app.activeDocument.activeLayer.kind != LayerKind.NORMAL) continue;

  for(var z in actionArray){

  try{

  doAction(actionArray[0].toString(), actionArray[1].toString());

  }catch(e){alert(e+" - "+e.line);}

  }

  }

 

};

win.center();

win.show();

 

function getActionSets() {

cTID = function(s) { return app.charIDToTypeID(s); };

sTID = function(s) { return app.stringIDToTypeID(s); };

  var i = 1;

  var sets = []; 

  while (true) {

  var ref = new ActionReference();

  ref.putIndex(cTID("ASet"), i);

  var desc;

  var lvl = $.level;

  $.level = 0;

  try {

  desc = executeActionGet(ref);

  } catch (e) {

  break; 

  } finally {

  $.level = lvl;

  }

  if (desc.hasKey(cTID("Nm "))) {

  var set = {};

  set.index = i;

  set.name = desc.getString(cTID("Nm "));

  set.toString = function() { return this.name; };

  set.count = desc.getInteger(cTID("NmbC"));

  set.actions = [];

  for (var j = 1; j <= set.count; j++) {

  var ref = new ActionReference();

  ref.putIndex(cTID('Actn'), j);

  ref.putIndex(cTID('ASet'), set.index);

  var adesc = executeActionGet(ref);

  var actName = adesc.getString(cTID('Nm '));

  set.actions.push(actName);

  }

  sets.push(set);

  }

  i++;

  }

  return sets;

};

 

function getActions(aset) {

cTID = function(s) { return app.charIDToTypeID(s); };

sTID = function(s) { return app.stringIDToTypeID(s); };

  var i = 1;

  var names = [];

  if (!aset) {

  throw "Action set must be specified";

  } 

  while (true) {

  var ref = new ActionReference();

  ref.putIndex(cTID("ASet"), i);

  var desc;

  try {

  desc = executeActionGet(ref);

  } catch (e) {

  break;

  }

  if (desc.hasKey(cTID("Nm "))) {

  var name = desc.getString(cTID("Nm "));

  if (name == aset) {

  var count = desc.getInteger(cTID("NmbC"));

  var names = [];

  for (var j = 1; j <= count; j++) {

  var ref = new ActionReference();

  ref.putIndex(cTID('Actn'), j);

  ref.putIndex(cTID('ASet'), i);

  var adesc = executeActionGet(ref);

  var actName = adesc.getString(cTID('Nm '));

  names.push(actName);

  }

  break;

  }

  }

  i++;

  }

  return names;

};

function snapShot() {

  var desc9 = new ActionDescriptor();

  var ref5 = new ActionReference();

  ref5.putClass( charIDToTypeID('SnpS') );

  desc9.putReference( charIDToTypeID('null'), ref5 );

  var ref6 = new ActionReference();

  ref6.putProperty( charIDToTypeID('HstS'), charIDToTypeID('CrnH') );

  desc9.putReference( charIDToTypeID('From'), ref6 );

  desc9.putEnumerated( charIDToTypeID('Usng'), charIDToTypeID('HstS'), charIDToTypeID('FllD') );

  executeAction( charIDToTypeID('Mk '), desc9, DialogModes.NO );

};

function hasLayerMask() {

  var ref = new ActionReference();

  ref.putEnumerated( stringIDToTypeID( "layer" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ));

  var Mask= executeActionGet( ref );

  return Mask.hasKey(charIDToTypeID('Usrs'));

};

function getSelectedLayersIdx(){

  var selectedLayers = new Array;

  var ref = new ActionReference();

  ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

  var desc = executeActionGet(ref);

  if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){

  desc = desc.getList( stringIDToTypeID( 'targetLayers' ));

  var c = desc.count

  var selectedLayers = new Array();

  for(var i=0;i<c;i++){

  try{

  activeDocument.backgroundLayer;

  selectedLayers.push( desc.getReference( i ).getIndex() );

  }catch(e){

  selectedLayers.push( desc.getReference( i ).getIndex()+1 );

  }

  }

  }else{

  var ref = new ActionReference();

  ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));

  ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

  try{

  activeDocument.backgroundLayer;

  selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);

  }catch(e){

  selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));

  }

  }

  return selectedLayers;

};

function makeActiveByIndex( idx, visible,add ){

  if(visible == undefined) visible = false;

  if(add == undefined) add=false;

  var desc = new ActionDescriptor();

  var ref = new ActionReference();

  ref.putIndex(charIDToTypeID( "Lyr " ), idx)

  desc.putReference( charIDToTypeID( "null" ), ref );

  if(add) desc.putEnumerated(stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelection'));

  desc.putBoolean( charIDToTypeID( "MkVs" ), visible );

  executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );

};

function selectAllLayers(layer) {

if(layer == undefined) layer = 0;

activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length-1];

var BL = activeDocument.activeLayer.name;

activeDocument.activeLayer = activeDocument.layers[layer];

  var desc5 = new ActionDescriptor();

  var ref3 = new ActionReference();

  ref3.putName( charIDToTypeID('Lyr '), BL);

  desc5.putReference( charIDToTypeID('null'), ref3 );

  desc5.putEnumerated( stringIDToTypeID('selectionModifier'), stringIDToTypeID('selectionModifierType'), stringIDToTypeID('addToSelectionContinuous') );

  desc5.putBoolean( charIDToTypeID('MkVs'), false );

  executeAction( charIDToTypeID('slct'), desc5, DialogModes.NO );

};

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 13, 2018 May 13, 2018

Copy link to clipboard

Copied

Fit image will work and the use of an action will save several steps. As to doing "all at once". Sort of. If you were always working with a set number of layer then the action could contain the steps to select each layer in turn.

As it is I have created 2 actions. One for any number of layers which may or may not be in order and one for layers in order, as you show.

Start at the bottom of the layer stack.

 

The action is here: download

dar-600px.atn

 

 

A silent video demonstrating the use of the action.

Note. You dont need to do the canvas resize part. That was just to show all layers at same height.

 

600px on Vimeo

 

Through some trial and error. I tested to see what would happen if the values in the fit image dialog were both 600px. The result is the long edge would be 600 and the short edge fall where it may. IE. It FITS it  into a 600x600 box.

The arbitrary value of 9000px I used was just that - arbitrary. But I discovered that the "discarded" or unnecessary value must be at least twice that of the value desired for it to be essentially ignored. In this case if you entered 1150 x 600. two of your layers would get to 1150 wide before they were 600 tall.

Go wild - the largest dimension you can enter is 300000 pixels.

Fit image is not the same as Image Size.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 14, 2018 May 14, 2018

Copy link to clipboard

Copied

Yup, that’s what I said, enter a huge amount for the dimensio that you do not want to affec in fit image, or in image processo...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 14, 2018 May 14, 2018

Copy link to clipboard

Copied

Thanks D.A.R. – did you upload the correct action?

The separate layers that are turned into a smart object are treated as a single object in the fit image resize, so the total bounding area is sized to 600px, not each individual element in each separate layer.

I am curious to see both of your actions as mentioned…

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 14, 2018 May 14, 2018

Copy link to clipboard

Copied

Stephen_A_Marsh  wrote

Thanks D.A.R  – did you upload the correct action?

The separate layers that are turned into a smart object are treated as a single object in the fit image resize, so the total bounding area is sized to 600px, not each individual element in each separate layer.

I am curious to see both of your actions as mentioned…

Yes, I have uploaded the actions shown in the video.

As far as "each individual element in each separate layer". I was treating the image in the layer as the object to resize. If there are multiple images per layer, that is not clear from the OP.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 14, 2018 May 14, 2018

Copy link to clipboard

Copied

Yes, I have uploaded the actions shown in the video.

As far as "each individual element in each separate layer". I was treating the image in the layer as the object to resize. If there are multiple images per layer, that is not clear from the OP.

D.A.R., OK, I found the issue – my test file was saved with both test layers selected/targeted… This layer selection was remembered when I opened up the file again later, so when I ran your “600px height” action, it converted both layers into a single smart object. When I target a single layer your action works correctly.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 14, 2018 May 14, 2018

Copy link to clipboard

Copied

LATEST

Stephen_A_Marsh  wrote

When I target a single layer your action works correctly.

Cool.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2018 May 08, 2018

Copy link to clipboard

Copied

File > Automate > Fit Image might also be useful.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

Hello, have you tried to give a huge number for the width?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

Copy it to notepad. Save as "Steady Height with Proportional Width.jsx" (incl. double quotes) into 'Presets / Scripts' of your Photoshop folder. Then (re)launch Ps and you will find this script in 'File / Scripts' menu. You may bind some shortcut to it, so any time you want to use this script you will just press some key(s) (in some cases you didn't specified it may not work):

preferences.rulerUnits = Units.PIXELS

function sTT(v) {return stringIDToTypeID(v)}

(ref = new ActionReference()).putEnumerated

(sTT('document'), sTT('ordinal'), sTT('targetEnum'))

len = executeActionGet(ref).getInteger(sTT('numberOfLayers'))

for(i = 1; i <= len;) {

     (ref = new ActionReference()).putIndex(sTT('layer'), i++)

     if (typeIDToStringID((dsc = executeActionGet(ref))

     .getEnumerationValue(sTT(lS = 'layerSection'))) == lS + 'Content') {

          (lst = new ActionList()).putReference(ref), dsc.putList(sTT('null'), lst)

          if (!dsc.getBoolean(sTT('visible'))) {

               executeAction(sTT('show'), dsc, DialogModes.NO)

          }

          (ref = new ActionReference()).putIndex(sTT('layer'), i - 1);

          (dsc = new ActionDescriptor()).putReference(sTT('null'), ref)

          executeAction(sTT('select'), dsc, DialogModes.NO)

          with(activeDocument.activeLayer) {

               resize(s = 600 / ((b = bounds)[2] - b[0]) * 100, s)

          }

     }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

Kukurykus  I just tried your script in CC2018 with 3 layers selected, only 1 of the 3 layers is being resized to 600px high. Unless I have misunderstood the OP, all selected layers need to be the same height at 600 pixels, maintaining their original aspect ratio/proportional width. Each selected layer needs to be resized independently.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 12, 2018 May 12, 2018

Copy link to clipboard

Copied

I wrote it in CS6 EXTENDED, but now tried in 19.1.3 version and it works too however you are right as I mistaken height with width. Now I corrected order, so layers won't be based on width, but height length. Additionally I added 'locked' layers case. So each time script meets them, they will be bypassed. Processing selected layers only version I will do a little later. Change:

resize(s = 600 / ((b = bounds)[2] - b[0]) * 100, s)

to

if (!positionLocked) resize(s = 600 / ((b = bounds)[3] - b[1]) * 100, s)

Here is mainly Action Manager ver. that does the same like previous one with correction (but still with no selected layers):

function sTT(v) {return stringIDToTypeID(v)}

function adl(v) {

     (ref = new ActionReference()).putEnumerated

     (sTT(v), sTT('ordinal'), sTT('targetEnum'))

}

adl('application'); if (typeIDToStringID(executeActionGet(ref)

.getEnumerationValue(sTT('rulerUnits'))) != 'rulerPixels')

     preferences.rulerUnits = Units.PIXELS

adl('document'), len = executeActionGet(ref).getInteger(sTT('numberOfLayers'))

for(i = 1; i <= len;) {

     (ref = new ActionReference()).putIndex(sTT('layer'), i++)

     if (typeIDToStringID((dsc = executeActionGet(ref))

     .getEnumerationValue(sTT(lS = 'layerSection'))) == lS + 'Content') {

          (lst = new ActionList()).putReference(ref), dsc.putList(sTT('null'), lst)

          function prtct(v) {

               return dsc.getObjectValue(sTT('layerLocking')).getBoolean(sTT(v))

          }

          if (!prtct('protectPosition') && !prtct('protectAll')) {

               bnds = dsc.getObjectValue(sTT('bounds'))

               if (!dsc.getBoolean(sTT('visible'))) {

                    executeAction(sTT('show'), dsc, DialogModes.NO)

               }

               (ref = new ActionReference()).putIndex(sTT('layer'), i - 1);

               (dsc = new ActionDescriptor()).putReference(sTT('null'), ref)

               executeAction(sTT('select'), dsc, DialogModes.NO)

               function h(v) {return bnds.getUnitDoubleValue(sTT(v))}

               if ((s = 600 / (h('top') - h('bottom')) * 100) < Infinity) {

                    function wh(v) {

                         dsc.putUnitDouble(sTT(v), sTT('percentUnit'), s)

                    }

                    wh('width'), wh('height'), executeAction

                    (sTT('transform'), dsc, DialogModes.NO)

               }

          }

     }

}

In previous script I prevented also transforming while processing empty layer. Here's a version where you can select layers:

function adl(v1, v2) {

     eval("(ref = new ActionReference()).put" + (!v2 ? "Enumerated" : "Index")

     + "(sTT(v1), " + (!v2 ? "sTT('ordinal'), sTT('targetEnum')" : I) + ")")

}

function prtct(v) {

     return dsc.getObjectValue(sTT('layerLocking')).getBoolean(sTT(v))

}

function prcs(v) {

     adl('layer', v); if (typeIDToStringID((dsc = executeActionGet(ref))

     .getEnumerationValue(sTT(lS = 'layerSection'))) == lS + 'Content') {

          (lst2 = new ActionList()).putReference(ref), dsc.putList(sTT('null'), lst2)

          if (!prtct('protectPosition') && !prtct('protectAll')) {

               bnds = dsc.getObjectValue(sTT('bounds'))

               if (!dsc.getBoolean(sTT('visible'))) {

                    executeAction(sTT('show'), dsc, DialogModes.NO)

               }

               if (v) (ref = new ActionReference()).putIndex(sTT('layer'), I);

               (dsc = new ActionDescriptor()).putReference(sTT('null'), ref)

               executeAction(sTT('select'), dsc, DialogModes.NO)

               function h(v) {return bnds.getUnitDoubleValue(sTT(v))}

               if ((s = 600 / (h('top') - h('bottom')) * 100) < Infinity) {

                    function wh(v) {

                         dsc.putUnitDouble(sTT(v), sTT('percentUnit'), s)

                    }

                    wh('width'), wh('height'), executeAction

                    (sTT('transform'), dsc, DialogModes.NO)

               }

          }

     }

}

function sTT(v) {return stringIDToTypeID(v)} $.level = 0

adl('application'); if (typeIDToStringID(executeActionGet(ref)

.getEnumerationValue(sTT('rulerUnits'))) != 'rulerPixels')

     preferences.rulerUnits = Units.PIXELS

try{

     (ref = new ActionReference()).putIdentifier(sTT('layer'), 1)

     bG = !(executeActionGet(ref)).getBoolean(sTT('background'))

}

catch (err) {bG = 1}

adl('document'), tL = sTT('targetLayers')

if ((dsc = executeActionGet(ref)).hasKey(tL)) {

     for(lst1 = dsc.getList(tL), i = 0; i < lst1.count; i++) {

          I = lst1.getReference(i).getIndex() + bG, prcs(true)

     }

}

else prcs()

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 13, 2018 May 13, 2018

Copy link to clipboard

Copied

And another script from Paul Riggott:

 

ResizeSelectedLayers.jpg

 

 

Resize Selected Layers.zip

 

//#target photoshop

function main(){

if(!documents.length) return;

var win = new Window( 'dialog', 'RL' );

g = win.graphics;

var myBrush = g.newBrush(g.BrushType.SOLID_COLOR, [0.99, 0.99, 0.99, 1]);

g.backgroundColor = myBrush;

win.orientation='stack';

win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});

win.g1 = win.p1.add('group');

win.g1.orientation = "row";

win.title = win.g1.add('statictext',undefined,'Resize Selected Layers');

win.title.alignment="fill";

var g = win.title.graphics;

g.font = ScriptUI.newFont("Georgia","BOLDITALIC",22);

win.g5 =win.p1.add('group');

win.g5.orientation = "row";

win.g5.alignment='left';

win.g5.spacing=10;

win.g5.st1 = win.g5.add('statictext',undefined,'Resize to...');

win.g5.et1 = win.g5.add('edittext');

win.g5.et1.preferredSize=[60,20];

resizeUnits = ["pixels", "inches","cm", "mm"];

win.g5.dd1 = win.g5.add('dropdownlist',undefined,resizeUnits);

win.g5.dd1.selection=0;

var resizeWH=["Width","Height"];

win.g5.dd2 = win.g5.add('dropdownlist',undefined,resizeWH);

win.g5.dd2.selection=0;

win.g5.et1.onChanging = function() {

  if (this.text.match(/[^\-\.\d]/)) {

    this.text = this.text.replace(/[^\-\.\d]/g, '');

  }

};

win.g7 =win.p1.add('group');

win.g7.orientation = "row";

win.g7.alignment='left';

var ResizeMethods=["Nearest Neighbour","Bicubic","Bilinear","Bicubic Smoother","Bicubic Sharper","Bicubic Automatic"];

if(app.version.match(/\d+/) <13) ResizeMethods=["Nearest Neighbour","Bicubic","Bilinear","Bicubic Smoother","Bicubic Sharper"];

var ResizeMethod=["nearestNeighbor","bicubic","bilinear","bicubicSmoother","bicubicSharper","bicubicAutomatic"];

win.g7.st1 = win.g7.add('statictext',undefined,'Resize Method');

win.g7.dd1 = win.g7.add('dropdownlist',undefined,ResizeMethods);

if(app.version.match(/\d+/) >12){

win.g7.dd1.selection=5;

}else{

    win.g7.dd1.selection=1;

    }

win.g10 =win.p1.add('group');

win.g10.orientation = "row";

win.g10.alignment='fill';

win.g10.spacing=10;

win.g10.bu1 = win.g10.add('button',undefined,'Process');

win.g10.bu1.preferredSize=[150,25];

win.g10.bu2 = win.g10.add('button',undefined,'Cancel');

win.g10.bu2.preferredSize=[150,25];

win.g10.bu1.onClick=function(){

if(win.g5.et1.text == ''){

    alert("You have not entered a required size!");

    return;

    }

win.close(0);

var origResizeMethod = resizeMethod();

//0 = Width 1 = Height

var WH = win.g5.dd2.selection.index;

Res = activeDocument.resolution;

Pixel = Number(win.g5.et1.text);

CM = Res/2.54;

MM = Res/25.4;

switch(win.g5.dd1.selection.index){

    case 0 : break;

    case 1 : Pixel = Pixel * Res; break;

    case 2 : Pixel = Pixel * CM; break;

    case 3 : Pixel = Pixel * MM; break;

    default : break;

    }

var selectedLayers = getSelectedLayersIdx();

var startRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

setResizeMethod(ResizeMethod[win.g7.dd1.selection.index].toString());

for (var z in selectedLayers){

selectLayerByIndex(Number(selectedLayers));

resizeLayer(Pixel,Number(WH));

    }

setResizeMethod(origResizeMethod);

app.preferences.rulerUnits = startRulerUnits;

}

win.center();

win.show();

}

main();

 

 

function resizeLayer(Pixel,WH){

var doc = activeDocument;

var res= doc.resolution;

var LB = activeDocument.activeLayer.bounds;

if(WH==1){

var Height = LB[3].value - LB[1].value;

var onePix = 100/Height;

}else{

var Width = LB[2].value - LB[0].value;

var onePix = 100/Width;

}

var newSize = onePix * Pixel;

doc.activeLayer.resize( newSize , newSize, AnchorPosition.MIDDLECENTER);

}

function selectLayerByIndex(index,add){

  add = (add == undefined)  ? add = false : add;

var ref = new ActionReference();

    ref.putIndex(charIDToTypeID("Lyr "), index);

    var desc = new ActionDescriptor();

    desc.putReference(charIDToTypeID("null"), ref );

      if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) );

      desc.putBoolean( charIDToTypeID( "MkVs" ), false );

  try{

    executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );

}catch(e){}

};

function getSelectedLayersIdx(){

      var selectedLayers = new Array;

      var ref = new ActionReference();

      ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

      var desc = executeActionGet(ref);

      if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){

        desc = desc.getList( stringIDToTypeID( 'targetLayers' ));

          var c = desc.count

          var selectedLayers = new Array();

          for(var i=0;i<c;i++){

            try{

              activeDocument.backgroundLayer;

              selectedLayers.push(  desc.getReference( i ).getIndex() );

            }catch(e){

              selectedLayers.push(  desc.getReference( i ).getIndex()+1 );

            }

          }

      }else{

        var ref = new ActionReference();

        ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));

        ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

        try{

            activeDocument.backgroundLayer;

            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);

        }catch(e){

            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));

        }

      }

      return selectedLayers;

};

function resizeMethod(){

var ref1 = new ActionReference();

ref1.putEnumerated( charIDToTypeID('capp'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

var resizeMethod =  typeIDToStringID(executeActionGet(ref1).getEnumerationValue(charIDToTypeID('IntM')));

return resizeMethod;

};

function setResizeMethod(Method) {

    var desc1 = new ActionDescriptor();

        var ref1 = new ActionReference();

        ref1.putProperty( charIDToTypeID('Prpr'), charIDToTypeID('GnrP') );

        ref1.putEnumerated( charIDToTypeID('capp'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );

    desc1.putReference( charIDToTypeID('null'), ref1 );

        var desc2 = new ActionDescriptor();

        desc2.putEnumerated( charIDToTypeID('IntM'), charIDToTypeID('Intp'), stringIDToTypeID(Method) );

        if(app.version.match(/\d+/) >12) desc2.putBoolean( stringIDToTypeID('legacyPathDrag'), true );

    desc1.putObject( charIDToTypeID('T  '), charIDToTypeID('GnrP'), desc2 );

    executeAction( charIDToTypeID('setd'), desc1, DialogModes.NO );

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 14, 2018 May 14, 2018

Copy link to clipboard

Copied

You can easily make your own action to set the height to 600px while retaining the original dimensions of the photo's:

  • In Actions Create a New Action and press the 'record' button.
  • Go to Image > Image Size and set the height to 600 pixels. The width will automatically adjust to the original dimensions if width and height are linked with 'constrain aspect ratio'. This is the default setting. Click OK.
  • In Actions stop recording.

Now you can play the action in the other photo's. Done!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 14, 2018 May 14, 2018

Copy link to clipboard

Copied

Thanks Marja, however the request is to proportionally resize multiple layers at different source heights to the same target pixel height, with the caveat being that they already exist in a document (not as separate files), preferably resizing with a “single command”.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines