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

Transform a group of layers to all reach the top and bottom of canvas

Community Beginner ,
Oct 21, 2022 Oct 21, 2022

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? 

happyplant1111_0-1666385573112.pngexpand image



Thank you!

Using PS 2021
Windows

TOPICS
Windows

Views

664

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 1 Correct answer

Community Expert , Oct 22, 2022 Oct 22, 2022

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);
  
...

Votes

Translate

Translate
Community Beginner ,
Oct 22, 2022 Oct 22, 2022

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. 

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 ,
Oct 22, 2022 Oct 22, 2022

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

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 ,
Oct 24, 2022 Oct 24, 2022

Copy link to clipboard

Copied

LATEST

@happyplant1111 - So how did the latest script from Chuck work for you?

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