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

Image resize script worked on some photos but not others

New Here ,
Nov 05, 2020 Nov 05, 2020

Copy link to clipboard

Copied

I ran a script that fit the image to 2500x2500 px and changed the canvas size to 2500x2500 px with a white background so that the different sized images all fit into squares with the remaining background white. This worked successfull for 75% of the photos, but the other 25% of them it didn't do anything. I have run the action again and for about 30 photos it will not do it. Any help why this is happening and how to fix it on the remaining photos?

TOPICS
Actions and scripting , Windows

Views

1.8K

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 , Nov 06, 2020 Nov 06, 2020

The Canvas size step needs to be re-recorded so both the width and height are recorded. The current step will only fix  landscape images height. Portrait width will not be fixed.

image.png

That is an action not a script. Scripting is a different Photoshop automation feature. You can programs Photoshop procedures. Actions are very limited in what they can do for they has just a few condition they can test and you need to record additional action for the conditions.  Actions can use Scripts and Scripts can

...

Votes

Translate

Translate
Adobe
Community Expert ,
Nov 05, 2020 Nov 05, 2020

Copy link to clipboard

Copied

If its a script post the script. If its an Action Expand the action and all the steps in the action in the actions palette and post a screen capture

JJMack

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 05, 2020 Nov 05, 2020

Copy link to clipboard

Copied

Nobody can help you unless we know which exactly script/action you are running and what is inside script/action. 

 

"but the other 25% of them it didn't do anything"

Do you mean action/script failed to execute steps or something else? We need more info and most likely action or script to examine.

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 06, 2020 Nov 06, 2020

Copy link to clipboard

Copied

Here is the script:

 

Screen Shot 2020-11-06 at 7.32.13 AM.png

 

It worked on most of the images, about 100 of them, with this as the final result:

 

Screen Shot 2020-11-06 at 7.30.32 AM.png

 

It did NOT execute for about 30 of them. I ran the script again on just the 30 that were left and still same result leaving the images as is in their various dimensions: 

 

Screen Shot 2020-11-06 at 7.31.55 AM.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 ,
Nov 06, 2020 Nov 06, 2020

Copy link to clipboard

Copied

The Canvas size step needs to be re-recorded so both the width and height are recorded. The current step will only fix  landscape images height. Portrait width will not be fixed.

image.png

That is an action not a script. Scripting is a different Photoshop automation feature. You can programs Photoshop procedures. Actions are very limited in what they can do for they has just a few condition they can test and you need to record additional action for the conditions.  Actions can use Scripts and Scripts can use Actions. However, what ever an action can do a script can also do. So the Photoshop Procedure can be in a single file.  Photoshop Scripting DOM doe not cover  all of Photoshop feature so even though script can use logic in their processing script often need to use Action Manager code to Script the Photoshop procedure.

 

 

An Action using using a Plug in Script can center crop an Image to a 1:1 aspect ratio and resize the crop to 2500x2500 to have no white boarders. This Action uses two plug-in scripts and Image crop.

image.png

JJMack

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 07, 2020 Nov 07, 2020

Copy link to clipboard

Copied

LATEST

If you follow JJMack's advice and re-record the canvas size step to contain both width and height entries all should be fine.

 

As an exercise, I hacked the following scripts together (not to be confused with actions)...

 

Resize image canvas to 2500px square with white bg.jsx (suitable for recording into an action for batch processing)

 

 

/*
Resize image canvas to 2500px square with white bg.jsx

https://community.adobe.com/t5/photoshop/image-resize-script-worked-on-some-photos-but-not-others/td-p/11572554

https://community.adobe.com/t5/photoshop/canvas-resize-to-square-for-a-large-number-of-images-using-script-e-g-image-is-currently-1020-x-600/td-p/6148635
https://coffeeshopped.com/2008/11/conditional-image-resizing-with-photoshop-and-javascript
*/

#target photoshop

// Save the current ruler units
var savedRuler = app.preferences.rulerUnits;

// Save the current background color picker values
var savedBackgroundColor = app.backgroundColor;

// Set ruler units to pixels
app.preferences.rulerUnits = Units.PIXELS;

// Set the background color to white
var bgCol = new SolidColor();
bgCol.rgb.red = 255;
bgCol.rgb.green = 255;
bgCol.rgb.blue = 255;
app.backgroundColor = bgCol;

// Set the active document
var doc = app.activeDocument;

// Set the target size in px
var targetWidth = 2500;
var targetHeight = 2500;

// Resize if height > width (portrait-mode) resize based on height.  otherwise, resize based on width (landscape-mode)
if (doc.height > doc.width) {
    doc.resizeImage(null, targetHeight, null, ResampleMethod.BICUBIC);
} else {
    doc.resizeImage(targetWidth, null, null, ResampleMethod.BICUBIC);
}

// Resize canvas to longest edge
doc.resizeCanvas(Math.max(doc.width, doc.height), Math.max(doc.width, doc.height));

// Restore the ruler units
app.preferences.rulerUnits = savedRuler;

// Restore the saved background color picker values
app.backgroundColor = savedBackgroundColor;

 

 

 

Resize image canvas to square with white bg via prompt.jsx (suitable for manual use for variable resizing)

 
/*
Resize image canvas to square with white bg via prompt.jsx

https://community.adobe.com/t5/photoshop/image-resize-script-worked-on-some-photos-but-not-others/td-p/11572554

https://community.adobe.com/t5/photoshop/canvas-resize-to-square-for-a-large-number-of-images-using-script-e-g-image-is-currently-1020-x-600/td-p/6148635
https://coffeeshopped.com/2008/11/conditional-image-resizing-with-photoshop-and-javascript
https://gist.github.com/MarshySwamp/3770f9f201814669fa33e7c72b31a47f
*/

#target photoshop

    (function () {

        // Save the current ruler units
        var savedRuler = app.preferences.rulerUnits;

        // Save the current background color picker values
        var savedBackgroundColor = app.backgroundColor;

        // Loop the input prompt until a number is entered
        var origInput;
        while (isNaN(origInput = prompt("Enter the square size in pixels:", "2500")));
        // Test if cancel returns null, then terminate the script
        if (origInput === null) {
            alert('Script cancelled!');
            return
        }
        // Test if an empty string is returned, then terminate the script 
        if (origInput === "") {
            alert('A value was not entered, script cancelled!');
            return
        }
        // Convert decimal input to integer
        var inputToInteger = parseInt(origInput);

        // Set ruler units to pixels
        app.preferences.rulerUnits = Units.PIXELS;

        // Set the background color to white
        var bgCol = new SolidColor();
        bgCol.rgb.red = 255;
        bgCol.rgb.green = 255;
        bgCol.rgb.blue = 255;
        app.backgroundColor = bgCol;

        // Set the active document
        var doc = app.activeDocument;

        // Resize if height > width (portrait-mode) resize based on height.  otherwise, resize based on width (landscape-mode)
        if (doc.height > doc.width) {
            doc.resizeImage(null, inputToInteger, null, ResampleMethod.BICUBIC);
        } else {
            doc.resizeImage(inputToInteger, null, null, ResampleMethod.BICUBIC);
        }

        // Resize canvas to longest edge
        doc.resizeCanvas(Math.max(doc.width, doc.height), Math.max(doc.width, doc.height));

        // Restore the ruler units
        app.preferences.rulerUnits = savedRuler;

        // Restore the saved background color picker values
        app.backgroundColor = savedBackgroundColor;

    })();
 
 
Note: There is no check or warning for resizing an image larger than the original, the target size is presumed to be smaller.
 

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