10 Replies Latest reply on Aug 17, 2016 11:00 PM by graphict2986600

    batch odd dimension images to square

    carleq Level 1

      Hi

       

      I have lots of images that are all different sizes and more coming.

       

      I need to create an action that makes these images square in px dimensions, with the new side dim. the dim. of the longest side.

       

      I need to add canvas (light gray) to the short side.

       

      I understand actions but not scripting.

       

      Thanks exceedingly.

        • 1. Re: batch odd dimension images to square
          JJMack Most Valuable Participant

          I have created a script which is a Photoshop Plugin which can be downloaded it is one of my scripts included in my crafting actions package. The Plugin Script name is "AspectRatioSelection.jsx" all you need do is record a two step action that uses it.  Step 1 AspectRatioSelection 1:1 centered replace 0 feather. Step 2 menu Image>Image Crop you can batch that action. If you do not want to crop the image you could in the action a new layer fill it with gray then do the selection and delete the square selection to let the image below show through. If you have to add canvas to the short sides as you write you need to write a simple script to add canvas to the short side so both width and height are equal leave the anchor point the center and the have the added canvas  color be gray. If you look at some of the simpler scripts in my package I think you will be able to figure out a how to do it. The script will not be hard to write. If you can not figure it out Photoshop ships with a Plugin called the "ScriptListener" this Plug-in is install and uninstalled to have Photoshop record scripts.  You can install it start Photoshop create a new document and the add canvas to the document then exit Photoshop. Uninstall the plugin then look on your desktop for you will find two Photoshop scrip files one VSB and one Javascript with two steps new document and add canvas.  From the javascript one it should be east to create a javascript function to add canvas.  All your script would need to do is find the current document's longest size and use the function to make both the wdith and height this size..  Use one of my simple scripts as a script template. Photoshop also shaips with some scripting guide PDF files.

           

          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 http://www.mouseprints.net/old/dpr/WM900x600.jpg

          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

          2 people found this helpful
          • 2. Re: batch odd dimension images to square
            Michael L Hale Level 5

            If I understand what you want, set the background color to your light grey then run this script with an open document.

             

            var savedRuler= app.preferences.rulerUnits;
            app.preferences.rulerUnits = Units.PIXELS;
            var w = app.activeDocument.width;
            var h = app.activeDocument.height;
            if(w>h) app.activeDocument.resizeCanvas (w, w, AnchorPosition.MIDDLECENTER);
            if(w<h) app.activeDocument.resizeCanvas (h, h, AnchorPosition.MIDDLECENTER);
            //if w==h already square
            app.preferences.rulerUnits = savedRuler;
            

            You should be able to call the script from an action and batch the action to process all your images at once.

            3 people found this helpful
            • 3. Re: batch odd dimension images to square
              carleq Level 1

              Mr Hale

               

              THE ANSWER. Thanks for workflow glue. Looks like this will work, and i'm beginning to understand scripts!

              • 4. Re: batch odd dimension images to square
                JJMack Most Valuable Participant

                Michael  you make it to easy for them how will they ever learn?

                • 5. Re: batch odd dimension images to square
                  carleq Level 1

                  JJMack,

                   

                  I could also mark this helpful because laughter is the soul's best medicine!

                   

                  Honestly, your original message was very resourceful.

                  • 6. Re: batch odd dimension images to square
                    JJMack Most Valuable Participant

                    carleq wrote:

                     

                    i'm beginning to understand scripts!

                    If you want to understand scripts better try these links  http://morris-photographics.com/photoshop/tutorials/scripting1.html and http://morris-photographics.com/photoshop/tutorials/scripting2.html  I found Trevor Morris. introduction and sample scripts a great starting point.  You may also want to look at my crafting actions package you may learns some thing about Actions as well as Scripts you don't know today.

                    • 7. Re: batch odd dimension images to square
                      zero.firefox

                      Michael,

                       

                      Could I possible ask you to make an adjustment to your otherwise perfectly working script.

                      My issue is that I have some images that are very low height and big width,

                      Is it possible to adjust the script to make it account for situation where

                      Width is higher that 3/1 ratio the image would be turned 45 degrees.

                      Your help is very much appreciated , that you in advance

                      Igor

                      • 8. Re: batch odd dimension images to square
                        JJMack Most Valuable Participant

                        Michael passed RIP.

                         

                        Honor his memory learn a little for him. It that would be easy to do. After step 2 add:

                         

                        if (app.activeDocument.width / app.activeDocument.height >= 3) { rotate canvas 45;}

                         

                        All you need to do is figure out the { rotate canvas 45 statement;} part and that statement must be before the setting of the w and h var for their values will depend on the  out come of the  if >= 3 rotate thing you add

                        • 9. Re: batch odd dimension images to square
                          zero.firefox Level 1

                          I am very sorry to hear that. RIP Michael

                          • 10. Re: batch odd dimension images to square
                            graphict2986600

                            Hi Carleq, I had the same problem with the batch square crop images.

                            I solved it through the action, not the script. I realized the handy photoshop action to make it easy and fast.

                             

                            You can download it here:

                            https://graphicriver.net/item/auto-crop-image/17492142?ref=GraphicTreasury

                             

                            It cuts square and circle region from the center of your photos.

                            You can work with any source aspect ratios and proportions, and use the batch processing without additional actions from user side.