How To Show The Image Resize Dialog

On a previous post, I asked about accessing the Menu item View On Screen https://forums.creativeclouddeveloper.com/t/help-with-view-fit-on-screen-batchplay/2207/2

which produced some good replies from @simonhenke and @ddbell with how to access the Menu items.

I thought I might be able to use approach to access the “Image Size dialog” but according to AM its not classed as a Menu Item.

Does anyone know how to convert the AM code into BatchPlay.

var d = new ActionDescriptor();
   d.putUnitDouble(stringIDToTypeID("width"), stringIDToTypeID("pixelsUnit"), app.activeDocument.width.as('px'));
   d.putBoolean(stringIDToTypeID("scaleStyles"), true);
   d.putBoolean(stringIDToTypeID("constrainProportions"), true);
   d.putEnumerated(stringIDToTypeID("interfaceIconFrameDimmed"), stringIDToTypeID("interpolationType"), stringIDToTypeID("bicubicSharper"));
   executeAction(stringIDToTypeID("imageSize"), d, DialogModes.ALL);
   app.displayDialogs = DialogModes.NO;
1 Like

Change the part of the batch play code from dontDisplay to display. It seems to work the same as changing DialogModes.NO to DialogModes.ALL from the AM code.

  "_options": {
     "dialogOptions": "display"
  }

So here is my function from Alchemist (but modified to be only the descriptor). Yours may look a little different depending on how you are using batchPlay to run.

function resizeImage(width,height){
    
return   {
      "_obj": "imageSize",
      "width": {
         "_unit": "pixelsUnit",
         "_value": width
      },
      "height": {
         "_unit": "pixelsUnit",
         "_value": height
      },
      "interfaceIconFrameDimmed": {
         "_enum": "interpolationType",
         "_value": "automaticInterpolation"
      },
      "_isCommand": false,
      "_options": {
         "dialogOptions": "display"
      }
   }    
       
}

Your code looks as though you are passing the width and height to the function and bypassing the “Image size” Dialog box. Am I Correct ?

I am trying to show the Dialog so the user can enter their own width and height dimensions.

I have tried to use your code omitting the width and height values but still cannot get the Dialog to show from a button click

async function ResizeImage() {

   const batchPlay = require("photoshop").action.batchPlay;
   const result = await batchPlay(
      [
         {
            "_obj": "imageSize",
            "width": {
               "_unit": "pixelsUnit"
            },
            "height": {
               "_unit": "pixelsUnit"
            },
            "interfaceIconFrameDimmed": {
               "_enum": "interpolationType",
               "_value": "automaticInterpolation"
            },
            "_isCommand": false,
            "_options": {
               "dialogOptions": "display"
            }
         }
      ], {
      "synchronousExecution": false,
      "modalBehavior": "fail"
   });
}

document.getElementById(“btnResize”).addEventListener(“click”, ResizeImage);

The one I posted will enter the sizes but also show the dialog so the user can change it if they want. You don’t need to do it that way. Just record how you want to do it and change dontDisplay to display and it will show the dialog. I’m guessing if you just delete the width and height keys from the descriptor then it will show the dialog without making any initial changes to the dimensions (haven’t tried it though).

I’ll run a quick test in a few hours. I have a 1,500 image batch test running right now so Photoshop is tied up for a little while :slight_smile:

You need to take out the width and height keys completely. If you have them in there then they need values. I just tested and this works.

async function ResizeImage() {

   const batchPlay = require("photoshop").action.batchPlay;
   const result = await batchPlay(
      [
         {
            "_obj": "imageSize",
            "interfaceIconFrameDimmed": {
               "_enum": "interpolationType",
               "_value": "automaticInterpolation"
            },
            "_isCommand": false,
            "_options": {
               "dialogOptions": "display"
            }
         }
      ], {
      "synchronousExecution": false,
      "modalBehavior": "fail"
   });
}

Thank you @ddbell I got your last version to work.

I still find myself getting a little confused with the structure of BatchPlay with all the [ and { }

@ddbell I have just returned to your example for showing the image Size Dialog because I have noticed that the Constrain proprortions part of the dialog is not enabled.

I have looked again at the above AM code and can see the option is in there but I just cannot figure out how to add it to the code example you gave.

The option in the AM code is …

d.putBoolean(stringIDToTypeID("constrainProportions"), true);

Can you help on this one please

ian

Have you tried adding
constrainProportions: true ?

Should work if you add it to the same hierarchy level as _obj etc. Just make sure the last key/value pair is ended by a comma

Record it in Alchemist. When recording change the width or height in the UI so it resizes it to something,… or else there is nothing to record. Also have constrain proportions on before hitting apply. Then it will then record the constrain proportions in Alchemist along with the width or height. Then just remove the width/height keys from the descriptor and leave in the constrain proportions key.

Thanks @simonhenke and @ddbell
I shall try your suggestions tomorrow. Just closing down for the night :sleeping:

Worked Thanks.

This also worked and I learnt alot from doing this as I could see exactly how this was returning the results

Thanks for your input on this