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

Resize Image During Place (but do it to long side not short side)

New Here ,
Nov 08, 2022 Nov 08, 2022

Copy link to clipboard

Copied

Lots of websites that I upload photos to require photos to be a specific size so I often find myself using photoshop to crop down a bunch of images (of all different sizes, aspect ratios & folder locations) to get them all to the same size & aspect ratio.

The workflow I use currently is to open a new photoshop file in my desired size and then drag and drop the images I want into the file. I have the "Resize Image During Place" checkbox selected in the preferences and "Skip Transform when Placing" unchecked. Each image gets placed into the canvas and is automatically resized so that the short edge of the image is equal to the short edge of the canvas, usually, this results in letterboxing so I hold alt and drag one off the corners to the edge of the canvas and then if needed move the image so that the content in the image looks the best at the new crop. Once I have everything placed I export layers to files to a new folder and I'm done.

My biggest frustration with that workflow is manually dragging the corner to make the image fill the canvas and get rid of the letterboxing, it doesn't seem like that much but that step takes by far the longest and the whole workflow would be so much quicker if there was a preference setting as part of the Resize Image During Place checkbox: that gave the option to choose to 
Fit Short Side or Fit Long Side. That way I could even check "Skip Transform when Placing" in the preference and only move/size where needed.

Short of that feature request does anyone have any tips or tricks for how they resize multiple images to one specific size?

Views

527

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
Adobe
Community Expert ,
Nov 08, 2022 Nov 08, 2022

Copy link to clipboard

Copied

Hi Erin, you are right, this would be a feature request, or creating a topic as an "idea" rather than a "discussion".

 

As this is a discussion, I would offer you a couple of scripts.

 

This script will proportionally resize to fit the active layer to the document width (content will therefore extend beyond the top and bottom of the canvas, resized from the middle centre reference point):

 

/* 
https://forums.adobe.com/thread/988084
https://community.adobe.com/t5/photoshop-ecosystem-discussions/trying-to-do-text-to-fit-the-width-of-the-canvas-dimensions/m-p/11589399
*/

// Resize Active Layer to Doc Width.jsx

#target photoshop

resizeToDocWidth();

function resizeToDocWidth() {
    if (!documents.length) return;
    var startRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    var doc = app.activeDocument;
    var dWidth = doc.width;
    var LB = activeDocument.activeLayer.bounds;
    var Width = LB[2].value - LB[0].value;
    var onePix = 100 / Width;
    var newSize = onePix * dWidth;
    doc.activeLayer.resize(newSize, newSize, AnchorPosition.MIDDLECENTER);
    app.preferences.rulerUnits = startRulerUnits;
}

 

While this script will proportionally resize to fit the active layer to the document height (content will therefore extend beyond the left and right of the canvas, resized from the middle centre reference point): 

 

// Resize Active Layer to Doc Height.jsx

#target photoshop

resizeToDocHeight();

function resizeToDocHeight() {
    if (!documents.length) return;
    var startRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    var doc = app.activeDocument;
    var dHeight = doc.height;
    var LB = activeDocument.activeLayer.bounds;
    var Height = LB[3].value - LB[1].value;
    var onePix = 100 / Height;
    var newSize = onePix * dHeight;
    doc.activeLayer.resize(newSize, newSize, AnchorPosition.MIDDLECENTER);
    app.preferences.rulerUnits = startRulerUnits;
}

 

Once installed, each script can be run from a keyboard shortcut.

 

Another possibility is to use the Script Events Manager to have one of these scripts automatically run whenever the placeEvent is triggered.

 

2022-10-27_12-23-24.png

 

The script could also be modified to work only on selected layers or to process all layers automatically.

 

Thinking out loud, conditional processing could also be added to the script so that it would automatically process landscape vs. portrait layers automatically so that you don't have to decide which script to run or set as the default.

 

Edit – Here is a conditional version of both scripts combined into one (works with a single selected layer):

 

#target photoshop

var layerBounds = activeDocument.activeLayer.bounds;
var layerWidth = layerBounds[2].value - layerBounds[0].value;
var layerHeight = layerBounds[3].value - layerBounds[1].value;

if (layerHeight > layerWidth) {
    // portrait orientation
    resizeToDocWidth();
} else {
    // landscape orientation
    resizeToDocHeight();
}


function resizeToDocWidth() {
    if (!documents.length) return;
    var startRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    var doc = app.activeDocument;
    var dWidth = doc.width;
    var LB = activeDocument.activeLayer.bounds;
    var Width = LB[2].value - LB[0].value;
    var onePix = 100 / Width;
    var newSize = onePix * dWidth;
    doc.activeLayer.resize(newSize, newSize, AnchorPosition.MIDDLECENTER);
    app.preferences.rulerUnits = startRulerUnits;
}

function resizeToDocHeight() {
    if (!documents.length) return;
    var startRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    var doc = app.activeDocument;
    var dHeight = doc.height;
    var LB = activeDocument.activeLayer.bounds;
    var Height = LB[3].value - LB[1].value;
    var onePix = 100 / Height;
    var newSize = onePix * dHeight;
    doc.activeLayer.resize(newSize, newSize, AnchorPosition.MIDDLECENTER);
    app.preferences.rulerUnits = startRulerUnits;
}

 

Hope this helps!

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 ,
Nov 08, 2022 Nov 08, 2022

Copy link to clipboard

Copied

This version of the previous conditional script will resize all layers to fit the canvas, proportionally resizing portrait or landscape orientation as required.

 

#target photoshop

function main() {

    // Select all layers except the Background layer
    app.runMenuItem(stringIDToTypeID('selectAllLayers'));

    ///// Process selected layers - from jazz-y /////
    var s2t = stringIDToTypeID;
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
    r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
    var lrs = executeActionGet(r).getList(p),
        sel = new ActionReference();
    for (var i = 0; i < lrs.count; i++) {
        sel.putIdentifier(s2t('layer'), p = lrs.getReference(i).getIdentifier(s2t('layerID')));
        (r = new ActionReference()).putIdentifier(s2t('layer'), p);
        (d = new ActionDescriptor()).putReference(s2t("target"), r);
        executeAction(s2t('select'), d, DialogModes.NO);

        var layerBounds = activeDocument.activeLayer.bounds;
        var layerWidth = layerBounds[2].value - layerBounds[0].value;
        var layerHeight = layerBounds[3].value - layerBounds[1].value;

        if (layerHeight > layerWidth) {
            // If layer height > width (portrait orientation)
            resizeToDocWidth();
        } else {
            // If layer width > height (landscape orientation)
            resizeToDocHeight();
        }


        function resizeToDocWidth() {
            if (!documents.length) return;
            var startRulerUnits = app.preferences.rulerUnits;
            app.preferences.rulerUnits = Units.PIXELS;
            var doc = app.activeDocument;
            var dWidth = doc.width;
            var LB = activeDocument.activeLayer.bounds;
            var Width = LB[2].value - LB[0].value;
            var onePix = 100 / Width;
            var newSize = onePix * dWidth;
            doc.activeLayer.resize(newSize, newSize, AnchorPosition.MIDDLECENTER);
            app.preferences.rulerUnits = startRulerUnits;
        }

        function resizeToDocHeight() {
            if (!documents.length) return;
            var startRulerUnits = app.preferences.rulerUnits;
            app.preferences.rulerUnits = Units.PIXELS;
            var doc = app.activeDocument;
            var dHeight = doc.height;
            var LB = activeDocument.activeLayer.bounds;
            var Height = LB[3].value - LB[1].value;
            var onePix = 100 / Height;
            var newSize = onePix * dHeight;
            doc.activeLayer.resize(newSize, newSize, AnchorPosition.MIDDLECENTER);
            app.preferences.rulerUnits = startRulerUnits;
        }

    }
}
app.activeDocument.suspendHistory("Fit Selected Layers to Canvas", "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
New Here ,
Nov 09, 2022 Nov 09, 2022

Copy link to clipboard

Copied

Thanks Stephen, I'm pretty new to scripts in photoshop but will give this a go.

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 ,
Nov 09, 2022 Nov 09, 2022

Copy link to clipboard

Copied

Hi Erin, just follow the link to my blogpost for info on saving/installing/running the script. Let the forum know if you have any issues.

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 ,
Nov 11, 2022 Nov 11, 2022

Copy link to clipboard

Copied

LATEST

@Erin Cloudy - So how did you go?

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 ,
Nov 09, 2022 Nov 09, 2022

Copy link to clipboard

Copied

@Erin Cloudy – Just to offer a different approach, one could use a Batch Action to create a Smart Object, then Automate > Fit Image command and a crop retaining pixels so that the layer can be adjusted as needed after the batch. This is obviously "flying blind" so reviewing the results in Bridge and then adjusting only the images that need extra work would be required. Batch saving from PSD to the final file format would be required.

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