Copy link to clipboard
Copied
Hello,
I am loading in a bunch of images of varying sizes. They scale to the sides by default in photoshop. However, for my purpose it would be better if they all scaled to the top and bottom. Is there any way to dfo this within photoshop natively, or a script to do this if not?
Thank you!
Using PS 2021
Windows
1 Correct answer
Okay, try this script. It will cycle through all the Smart Object layers at the top level and resize them. It will not do any layers in groups.
#target photoshop
var doc = activeDocument
app.preferences.rulerUnits = Units.PIXELS;
var layBounds
for(var i=0;i<doc.layers.length;i++){
doc.activeLayer = doc.layers[i];
layBounds = doc.activeLayer.bounds;
if(doc.activeLayer.kind == 'LayerKind.SMARTOBJECT'){
var ratio =doc.height.value/ (layBounds[3].value-layBounds[1].value);
...
Explore related tutorials & articles
Copy link to clipboard
Copied
This is prior to adding any images. The "ART" group at the bottom with the hidden mask is where they are added to when saving.
Copy link to clipboard
Copied
Okay, try this script. It will cycle through all the Smart Object layers at the top level and resize them. It will not do any layers in groups.
#target photoshop
var doc = activeDocument
app.preferences.rulerUnits = Units.PIXELS;
var layBounds
for(var i=0;i<doc.layers.length;i++){
doc.activeLayer = doc.layers[i];
layBounds = doc.activeLayer.bounds;
if(doc.activeLayer.kind == 'LayerKind.SMARTOBJECT'){
var ratio =doc.height.value/ (layBounds[3].value-layBounds[1].value);
doc.activeLayer.resize (ratio *100, ratio*100);
layBounds = doc.activeLayer.bounds;
var soCenterX = (layBounds[0].value + layBounds[2].value)/2
var soCenterY = (layBounds[1].value + layBounds[3].value)/2
doc.activeLayer.translate ((doc.width.value/2)-soCenterX, (doc.height.value/2)-soCenterY)
}
}//end for loop
Copy link to clipboard
Copied
@happyplant1111 - So how did the latest script from Chuck work for you?
![](/skins/images/FC087885B0C83B45128AF5065A4AB513/responsive_peak/images/icon_anonymous_message.png)
![](/skins/images/FC087885B0C83B45128AF5065A4AB513/responsive_peak/images/icon_anonymous_message.png)
-
- 1
- 2