0

I have a collage-like image in Photoshop with 35 layers. On each layer is a picture, and each picture is a different size (with different dimensions). I want to change the height of every layer so that they are all 200px (currently they range from 350 to 1200), without manually doing this one layer at a time.

I have tried using actions but that sets it by percentage, not pixels (and not only the height).

I have tried selecting all layers and then entering free edit (ctrl T) but this edits all layers in relation to one another.

I tried Export Layers to Files, so that I could then use the image processor script, but this keeps the canvas size as it is.

1

There's no a function like this in vanilla Photoshop to my knowledge, I'd go with a script: it's quite straightforward. The idea is to iterate through selected layers and proportionally scale them depending on their height.

Here's the script result (I was changing all layers to height of 50px):

enter image description here

And the script itself. To use it save this to a FileName.jsx to your Photoshop/Presets/Scripts folder, restart PS and you'll find name in the File > Scripts > FileName menu.

var size = 50; // result height

var layers = getLayers();

for (var i = 0; i < layers.length; i++)
{
  selectById(layers[i].id)
  transform(layers[i], size)
}

function selectById(id)
{
  var desc1 = new ActionDescriptor();
  var ref1 = new ActionReference();
  ref1.putIdentifier(charIDToTypeID('Lyr '), id);
  desc1.putReference(charIDToTypeID('null'), ref1);
  executeAction(charIDToTypeID('slct'), desc1, DialogModes.NO);
  return this;
}

function getLayers()
{
  var lyrs = [];
  var lyr;
  var ref = new ActionReference();
  var desc;
  var bounds;
  var tempIndex;
  var ref2;
  ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("targetLayers"));
  ref.putEnumerated(charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));  
  var targetLayers = executeActionGet(ref).getList(stringIDToTypeID("targetLayers"));
  for (var i = 0; i < targetLayers.count; i++)
  {
    lyr = {};
    tempIndex = 0;
    ref2 = new ActionReference();
    try
    {
      activeDocument.backgroundLayer;
      ref2.putIndex(charIDToTypeID('Lyr '), targetLayers.getReference(i).getIndex());
      desc = executeActionGet(ref2);
      tempIndex = desc.getInteger(stringIDToTypeID("itemIndex")) - 1;
    }
    catch (o)
    {
      ref2.putIndex(charIDToTypeID('Lyr '), targetLayers.getReference(i).getIndex() + 1);
      desc = executeActionGet(ref2);
      tempIndex = desc.getInteger(stringIDToTypeID("itemIndex"));
    }
    bounds = desc.getObjectValue(stringIDToTypeID("bounds"));
    lyr.id = desc.getInteger(stringIDToTypeID("layerID"));
    lyr.height = bounds.getDouble(stringIDToTypeID("height"));
    lyr.width = bounds.getDouble(stringIDToTypeID("width"));
    lyrs.push(lyr);
  }
  return lyrs;
}

function transform(layer, size)
{
  var sizeValue = size / layer.height * 100;
  var desc = new ActionDescriptor();
  var ref = new ActionReference();
  ref.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
  desc.putReference(cTID('null'), ref);
  desc.putEnumerated(cTID('FTcs'), cTID('QCSt'), cTID('Qcsa'));
  desc.putUnitDouble(cTID('Wdth'), cTID('#Prc'), sizeValue);
  desc.putUnitDouble(cTID('Hght'), cTID('#Prc'), sizeValue);
  desc.putEnumerated(cTID('Intr'), cTID('Intp'), cTID('Blnr'));
  executeAction(cTID('Trnf'), desc, DialogModes.NO);
} // end of transform()

| improve this answer | |
0

Here's a scriptless workaround if you're not comfortable with scripts.

  1. Quick export as PNG to save all layers individually.
  2. Make an action that changes height in Image Size to 200 px. Do not change anything else in the Image Size dialog box.
  3. Batch execute the action on all of the PNG files.

You can then use 'Load files into stack' to put them all in one document for easy managing.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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