12 Replies Latest reply on Jul 6, 2017 6:46 PM by JJMack

    Crop to Widest Dimension of Selection

    sameasterling

      Image > Crop will crop the image to a selection, but I need to crop to the selections widest dimension only, creating a square image. Anybody know of a way to accomplish this?

        • 1. Re: Crop to Widest Dimension of Selection
          JJMack Most Valuable Participant

          An image have one width.  A square crop is a 1:1 aspect ratio selection. Portraits aspect ratio image can be crop square to its width dimension with a 1:1 aspect ratio selection.. Which crop would you want. Landscape Images  can not be cropped square to their width size.  A 1:1 Aspect selection the width of a Landscape image would exceed the image's canvas size.

           

          You can make a 1:1 aspect ratio selection in an image in either orientation.  The max size for a portrait would be a 1:1 selection the is the width of the image and the max size in a landscape would be the height of the landscape.  The selected area can me anywhere in the image canvas.

          1 person found this helpful
          • 2. Re: Crop to Widest Dimension of Selection
            c.pfaffenbichler Level 9

            I would recommend a Scripting approach.

            Photoshop Scripting

            • 3. Re: Crop to Widest Dimension of Selection
              JJMack Most Valuable Participant

              In my crafting action package I include a Plug-in script I wrote for making aspect Ratio selections or paths that are rectangular or oval.  The Plug-in records the Aspect Ratio you set in the action step dialog when you record the action step. No dialog is displayed when your action plays. Its like scripted  marguee and path tool. The selection is set respective to the Image orientation the selection will have the image's orientation or be square or round.  The Aspect Ratio is not a width height thing it is a ratio. the Script take into account the image orientation and set the best selection for the image.  For portraits do not crop well to a landscape orientation and landscaped do not crop to portrait orientation well too much content would be cropped off the resulting composition will not be acceptable in general.

               

              A two step action will do  or you can do the two steps in Photoshop UI.

              Automate Aspect Ratio Selection

              Image Crop

               

              Capture.jpg

               

              Crafting Actions Package UPDATED Aug 10, 2014 Added Conditional Action steps to Action Palette Tips.
              Contains

              Example
              Download

              • 4. Re: Crop to Widest Dimension of Selection
                Randy Hufford Adobe Community Professional

                Lightroom would probably be the easiest solution. From the develop module crop first image with a 1;1 ratio. Than select all images and sync cropping to all images. You can than go to each image and move the crop to best look. How to Crop and Resize Photos for Slideshow in Adobe Lightroom - YouTube

                • 5. Re: Crop to Widest Dimension of Selection
                  JJMack Most Valuable Participant

                  Something like that may work in a case when all images are the same size and orientation.  IMO most user have image the have various aspect ratios and have both Portraits and Landscape image and me even have stitched images.   I do not use Lightroom so I have not Idea what would be the best approach to use in Lightroom

                   

                  In Photoshop I create Slideshow for 10 different Display devices is a single run of the Image Processor Pro Pulg-in in conjunction with my plug-in. Why would one want a square sideshow?  You want them for the device that will be displaying them. No all 16:9 or 1080P etc. For example for my surface pro 3  will create image file with an ar of 3 ant 2. Portraits will have a width of 1440 and a height or 2160 where Landscapes will have a width of 2160 and a height of 1440,  You rotate the Surface pro 3 to the correct orientation for the image being displayed. Image for mt 4k display will have a 16 9 aspect ratio and landscape images will display  3840x2160px where the 2160x3840 portraits are fitted to the displays height of 2160

                  • 6. Re: Crop to Widest Dimension of Selection
                    sameasterling Level 1

                    The images contain paths, so they can be converted to selections and used to base the crop on. The images could be landscape or portrait though, and I need a 1:1 crop based on the widest dimension.

                    • 7. Re: Crop to Widest Dimension of Selection
                      c.pfaffenbichler Level 9

                      What if the square would exceed beyond the Canvas?

                      • 8. Re: Crop to Widest Dimension of Selection
                        c.pfaffenbichler Level 9

                        // 2017, use it at your own risk;

                        #target photoshop

                        if (documents.length > 0) {cropAquare ()};

                        ////// function //////

                        function cropAquare () {

                        var myDocument = app.activeDocument;

                        try {

                        // do stuff;

                        var originalRulerUnits = app.preferences.rulerUnits;

                        app.preferences.rulerUnits = Units.PIXELS;

                        var theBounds = myDocument.selection.bounds;

                        var theWidth = theBounds[2] - theBounds[0];

                        var theHeight = theBounds[3] - theBounds[1];

                        var xC = theBounds[0] + theWidth/2;

                        var yC = theBounds[1] + theHeight/2;

                        var theMaxHalf = Math.max(theWidth, theHeight)/2;

                        var x1 = xC - theMaxHalf;

                        var y1 = yC - theMaxHalf;

                        var x2 = xC + theMaxHalf;

                        var y2 = yC + theMaxHalf;

                        // crop;

                        cropTo(x1, y1, x2, y2);

                        } catch (e) {}

                        };

                        ////// crop //////

                        function cropTo (x1, y1, x2, y2) {

                        // =======================================================

                        var idCrop = charIDToTypeID( "Crop" );

                            var desc7 = new ActionDescriptor();

                            var idT = charIDToTypeID( "T   " );

                                var desc8 = new ActionDescriptor();

                                var idPxl = charIDToTypeID( "#Pxl" );

                                desc8.putUnitDouble( charIDToTypeID( "Top " ), idPxl, y1 );

                                desc8.putUnitDouble( charIDToTypeID( "Left" ), idPxl, x1);

                                desc8.putUnitDouble( charIDToTypeID( "Btom" ), idPxl, y2 );

                                desc8.putUnitDouble( charIDToTypeID( "Rght" ), idPxl, x2 );

                            var idRctn = charIDToTypeID( "Rctn" );

                            desc7.putObject( idT, idRctn, desc8 );

                            desc7.putUnitDouble( charIDToTypeID( "Angl" ), charIDToTypeID( "#Ang" ), 0.000000 );

                            desc7.putBoolean( charIDToTypeID( "Dlt " ), false );

                            desc7.putEnumerated( stringIDToTypeID( "cropAspectRatioModeKey" ), stringIDToTypeID( "cropAspectRatioModeClass" ), stringIDToTypeID( "pureAspectRatio" ) );

                            desc7.putBoolean( charIDToTypeID( "CnsP" ), false );

                        executeAction( idCrop, desc7, DialogModes.NO );

                        };

                        • 9. Re: Crop to Widest Dimension of Selection
                          JJMack Most Valuable Participant

                          sameasterling  wrote

                           

                          The images contain paths, so they can be converted to selections and used to base the crop on. The images could be landscape or portrait though, and I need a 1:1 crop based on the widest dimension.

                          How many paths? Do you want to duplicate the document for each path and save a square image for each path and name the file something like DocNamePathName.   Or do you want to examine all the paths and select the one with the widest selection bounds paths can be any shape they do have a bounds width and height . When the current canvas size it too small do you want to add empty canvas instead of cropping some content off?? Crops and canvases are rectangular.

                          • 10. Re: Crop to Widest Dimension of Selection
                            norman.sanders Adobe Community Professional & MVP

                            Sometimes, despite the obvious efficiency of scripts and plug-ins, there is satisfaction of solving a problem using only Photoshop regular tools . Here is one such solution, doing the work on a duplicate of the original file.

                            square1.jpg

                            1. Cmd+J to place the selected element on a separate layer

                            2. Choose both layers. Choose the Move tool. Options bar: Align vertical centers followed by Align horizontal centers. Un-choose both layers. Choose Layer 1 and dupe it. Turn off the Background layer.

                            3. Choose Layer 1 Copy. Edit > Transform > Rotate 90 Degrees

                            4. Choose Layer 1 and Layer 1 Copy. Image > Trim …Transparent pixels. Then un-choose the layers, choose Layer 1 Copy and drag it to the trash.

                            • 11. Re: Crop to Widest Dimension of Selection
                              sameasterling Level 1

                              There is only one path, the path will never be larger than the document.

                              • 12. Re: Crop to Widest Dimension of Selection
                                JJMack Most Valuable Participant

                                Then script it an action can not do it.