Skip to main content
February 23, 2011
Answered

Select a tool preset depending on image orientation

  • February 23, 2011
  • 2 replies
  • 3976 views

Hi guys,

I wonder if you can have Photoshop select a tool preset depending on the orientation of the image.

E.g., if the selected tool is the Crop tool and the image "in focus" is a landscape, it selects the "15x10cm"   tool preset; after you crop and save this image, Photoshop switches to the next image, and if this is a portrait,  it selects the "10x5cm"  tool preset, and so on...

It is important that Crop tool presets to be loaded only if the crop tool is selected, because if not you would get the crop tool selected when you don't have any intention to crop the image.

Many thanks,

Ed

This topic has been closed for replies.
Correct answer Michael_L_Hale

Hi JJ,

Thank you very much for the effort you put in trying to find an answer to my question, but I'm afraid this is not what I'm looking for.

There's no time for rotating and transforming selection boxes in my workflow: there's nothing creative in it, you just have to choose which side to crop the images from (left/right and top/bottom, respectively). It's a very straightforward process, but the fact that I have to continually click the "Swap" button is annoying (we're talking about thousands of images).

I just need Photoshop to realize that the current image  has a different orientation than the previous one and automatically "Swap Height and Width"  for the Crop tool.

Have a great weekend,

Ed


Here is an script event manager script that will choose the crop tool preset depending on orientation. You will need to edit the tool preset names to match what is on your system.

function _selectDocumentHandler(desc) {
     var currentTool = getCurrentTool();
     if( currentTool == 'cropTool' ){
          var defaultRulerUnits = app.preferences.rulerUnits;
          app.preferences.rulerUnits = Units.PIXELS;
          var doc = app.activeDocument;
          var w = doc.width;
          var h = doc.height;
          if( w>h ){
               selectPreset('Crop Tool 8 in x 6 in');
          }else{
               selectPreset('Crop Tool 6 in x 8 in');
          }
          app.preferences.rulerUnits = defaultRulerUnits;
     }
};
function getCurrentTool(){
   var ref = new ActionReference();
   ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
   return typeIDToStringID(executeActionGet(ref).getEnumerationType(stringIDToTypeID('tool')));
};
function selectPreset(setName){
     var desc = new ActionDescriptor();
     var ref = new ActionReference();
     ref.putName( stringIDToTypeID( "toolPreset" ), setName );
     desc.putReference( charIDToTypeID( "null" ), ref );
     executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
};
try {
  if (arguments.length >= 2) {
    var desc = arguments[0];
    var event = arguments[1];
    if (event == charIDToTypeID('slct')) {
      var ref = desc.getReference(charIDToTypeID('null'));
      var cls = ref.getDesiredClass();
      if (cls == charIDToTypeID('Dcmn')) {
        _selectDocumentHandler(desc);
      }
    }
  }
} catch (e) {
  alert( "Error: " + e + ":" + e.line );
}

2 replies

February 23, 2011

If this is not obvious by now, I don't need a script that will crop the images automatically, I want to manually select the crop area, as the original images have a different aspect ratio.

I also now that I can filter the images in Bridge by aspect ratio and load in Photoshop images of a certain orientation at one time, but I'm interested to know if a scripted solution is viable.

JJMack
Community Expert
Community Expert
February 23, 2011

Ed

I don't understand what you are asking what your trying to do or are comming from.

Are you trying to create a script or action to automate some sort of batch crop.  Tool presets are set for you convience for when you want to manuall use a tool. With scripting you can use the document height and width  in logic therefor know the orintation. A script can crop using  a crop method one to four arrays are used cropping (Bounds[, angle] [,width] [,height]). Scripts can also set selection  based on orintation.

What are you trying to do tell us with words not tools or presets what are you trying to do.

JJMack
February 23, 2011

Hi JJMack,

Thank you for your prompt reply. I'll try to reformulate:

I  have to crop 60 images to be printed to 8x6". The images have a random  orientation: some are 'landscape', some are 'portrait'.

What  I do now is click the "Swap height and width" icon on the Crop tool's  toolbar when the next image does not have the same orientation as the  image that I have just cropped.

To speed up the workflow, I would like to use two tool presets:

a <Crop to 8"x6">  tool preset for landscape images and a <Crop to 6"x8"> tool preset for portrait images

and have Photoshop select the appropriate tool preset depending on image orientation.

It  would obviously be necessary that the script does this only when I  want to crop images - or it would always select the Crop tool for every  new image, even when I don't need it. That's why I'm thinking to have  the script select these presets only if the Crop tool is selected.

Something like this, if you pardon my French :

1.When the image 'gains focus' (i.e. when Photoshop switches to a new  image tab after loading images / saving an image / closing an image)

2. If selected tool is the Crop tool

3. Check image orientation and

4. If W>H, load the <Crop to 8"x6"> tool preset;   

    If W<H,  load the <Crop to 6"x8"> tool preset.

I hope I managed to clarify this.

Many thanks,

Ed

JJMack
Community Expert
Community Expert
February 23, 2011

Ed

I have a solution for you.  If you download my Crafting Action Package and install the scripts included in the package you can use two of the scripts in an action and do what you want to do. Set a shortcut for easy access.  The two Scripts are Photoshop Plug-ins and will be found as items in menu File>Automate>Item.    Where the items are "Aspect Ratio Selection..." and "Long Side Print Length...". Shoult look something like this:

The action you need to record is quite simple no more then five steps.

Step 1 menu File>Automate>Aspect Ratio Selection..."

Step 2 Free Transform

Step 3 menu Image>Crop

Step 4 menu File>Automate>Long Side Print Length...

Step 5 menu Image>Size

Now when you record the action steps 1,2, 4 and 5 will display dialogs which must be filled in correctly.  The settings will be recorded into the action and be used when the action is played without displaying any dialog.

Step 5 Dialog should be familiar to you and this step is only needed it you want the crop to be resampled to some DPI. You check resample the interpolation method you want to use and the DPI you want the corp to have.

Step 4 dialog is simple you just enter the length you want the crop to print at.  The script will set the correct DPI to print the crop that size without resampling the Crop.

Step 2 Ctrl-T in the opttion bar enter 180 as the angle and click OK turn on this steps dialog so you can manually modify the active 4:3 (8:6) aspect ratio selection. The 180 was to enable you to just accept the maximun size center selection so the transform would not be canceled when you hit enter.  To maintain the aspect ratio when your transforming the selection hold down the shift key an drag one of the cornor points. If you additionally hold the alt key all sides will move and the transform will be from the center. You can move the mouse pointer inside the selection hold the left mouse button and drag the selection about. Should you make a mistake hit the ESC key this will cancel the transform and the action will stop in the transform step. Click the Play button try doing the transform correctly.   I know this is not the crop tool. I never use the crop tool I'm too error prone with it.

Step one dialog is a bit more complex it looks like this:

You enter in the Aspect Ratio section enter 4 and 3 or 3 and 4 or 8 and 6 or 6 and 8 to the script they are all the same. For the script was written to maintain the images orintation and use any aspect ration entered  with respect for the images orintation.

Selection Options check center if you want the selection to be a center crop else the selection will start from the top left corner.  Make sure border is not checked you want the largest possible selection.

Selection shape for a crop choose rectangle the crop will be a rectangle even if you choose ellipse.

Selection type choose replace you want this to be the only selection.

Feather amount 0 for a crop Anti-Alias un-checked

http://www.mouseprints.net/old/dpr/JJMacksCraftingActions.zip

Contains:

Action Actions Palette Tips.txt

Action Creation Guidelines.txt

Action Dealing with Image Size.txt

Action Enhanced via Scripted Photoshop Functions.txt

CraftedActions.atn Sample Action set includes an example Watermarking action

Sample Actions.txt Photoshop CraftedActions set saved as a text file. This file has some additional comments I inserted describing how the actions work.

12 Scripts for actions

JJMack