22 Replies Latest reply: Aug 19, 2012 8:16 AM by JJMack RSS

    Cropping different file sizes script

    ocphotog Community Member

      I'm trying to come up with a way to have an action and script that will let me crop an image to 8x10 or 5x7 for example. What happens though is that if the image is a different size (resolution wise) when the action stops to allow me to do the crop, the crop guides will be a different size (depending on the initial resolution of the action set up image) or location on the image causing me to move the handles to get it back in to the new image. I would like the have the crop guides centered over the image in proportion to whatever resolution the image is. Can this be done?

        • 1. Re: Cropping different file sizes script
          c.pfaffenbichler Community Member

          Mind sharing a few more details or the Script you currently use?

          • 2. Re: Cropping different file sizes script
            ocphotog Community Member

            Sure,

            The action does a fit to screen then calls the 8x10 crop.js to determing if it's a vertical or horizontal image.

             

            8x10 crop.js:

            if (activeDocument.width > activeDocument.height)

            doAction("Horizontal","Crop to 8x10 Format.atn");

            else if (activeDocument.width < activeDocument.height)

            doAction("Vertical","Crop to 8x10 Format.atn");

             

             

            this script runs the action for vert or horiz with crop tool set at 8x10 with no resolution set. Where it get placed on the image varies depending on the original size the image is since it could have been based on an older cameras file size at the time the action was made.

             

            It's pretty basic I guess.

            • 3. Re: Cropping different file sizes script
              JJMack CommunityMVP

              You should be able to create an action to do that using my Plug-in Script AspectRatioSelection. You can automate a center crop or set upa  a center selection that is transformed 180 degrees and the transform step  made interactive. Hitting enter will accept the current sselection. If you do not like te selection you can move and transform it. Holding the Shift ket will constrain the transform to its current Aspect Ratio once you commit the selection the action will then crop the image. Once cropped the action would then use my second Plug-in script LongSidePrintLength to set the images print DPI so the image will print the size you want without resampling it. These scripts are in my crafting action package.

               

              Crafting Actions Package UPDATED Aug 14, 2012 Changed AspectRatioSelection Plug-in script added Path support.

              Contains

              Example

              Download

              • 4. Re: Cropping different file sizes script
                ocphotog Community Member

                Thanks for the suggestions. I did figure out that I needed to set the rulers to % when I did the initial crop so that same % would apply to other size files. Works fine now.

                • 5. Re: Cropping different file sizes script
                  JJMack CommunityMVP

                  I happy you found something that  works for you.  You stated " I'm trying to come up with a way to have an action and script that will let me crop an image to 8x10 or 5x7 for example." Are you using a action that uses a script if so are you seting ruler units to % for the action or the script or both. 

                   

                  How does percentage help with making aspect ratio crops. I would think Percent would only work if all your image had the same aspect ratio and orintation to begin with.  If you have images that have different aspect ratios I think your Action + Script might have some poblems. 

                   

                  For examp images from point and shoot cameras have aspect ration 4:3 and perhaps wide ones 16:9 where image from DSLR have a 3:2 aspect ratio. Also some images are in portrait orintation and some are in landscape orintation.  You may have also cropped some images to an unknown aspect ratio. Are you sure you have tested your solution well???

                  • 6. Re: Cropping different file sizes script
                    ocphotog Community Member

                    I have an action for an 8x10 crop and an action for a 5x7 crop.

                    I have 2 more action sets, one for 8x10 and one for 5x7. Inside each of those sets is an action for vertical, and one for horizontal, with cropping steps (the rulers are set to % and the crop tool is set to 8x10 when originally run) in each action.

                     

                    For example, for an 8x10 crop

                     

                    When the action is run it calls a script (8x10 crop) to determine if it's vertical or horizontal. The script tells to run either vertical action or horizontal action depending on the orientation. The action runs the crop centered on the image, pausing to adjust if necessary.

                     

                    My problem before was that when I created the original crop I had the rulers set to inches instead of percent, and I cropped from the top left to the bottom right. This time around I set the rulers to %, and did a center crop on the image. Haven't encountered any side effects so far on files from 3 different camera files I use that are different sizes, but probably the same aspect ratio.

                    • 7. Re: Cropping different file sizes script
                      ocphotog Community Member

                      Man, I hate it when you're always right!  I just tried to do the crop 8x10 crop action on an image that was already 8x10 and I got a distorted image. Bummer! Now I need around that little glitch should I get some images in a different format than I'm using now.

                      • 8. Re: Cropping different file sizes script
                        JJMack CommunityMVP

                        Actually I'm wrong more the I'm right for I can not type and make more errors the the average bear. 

                         

                        If you download my cafteing actions package, It would be very easy to record actions to do 8x10, 4x5, 5x7 etc center crops that requires no user intervention. One action for each size you want to create.

                         

                        You could then with a single run of the Image Processor Pro plug-in script (found on Russell Brown's web site) create  8x10, 4x5, 5x7 images for all your images in an image tree. You just need to take a long cofee break while the script runs your images throught the corpping actions you have recorded.

                        • 9. Re: Cropping different file sizes script
                          JJMack CommunityMVP

                          As I wrote the action to do center crops that require no user intervention are very easy to record in fact they are all identical with the exception that the two plug-in script steps need to be re-recorded to change the settings the step uses. The action is all of three steps so its just as easy to record a whole new action.

                           

                          Step 1 menu File>Automate.AspectRatioSelection

                          Step 2 menu Image>Crop

                          Step 3 menu File>Automate>LongSidePrintLength

                           

                          The plug-in scripts are based on Adobe plug-in "Fit Image"   You need not worry about the images orintation, All you need do is record two numbers for the ratio like 4 5.   If the current image is a portrait image the script creates a 4:5 aspect ratio selection if its a landscape it will create a 5:4 selection. All you need to do is record the aspect ratio you want to crop the image to.    Size does not matter. For example 8"x10", 4"x5" and 16"x20" all have an image aspect ratio of 4:5.

                           

                          Once you have the image cropped to the correct aspect ratio  you then need to set its print DPI to the correct setting so it will print the size you want.

                           

                          get it???

                           

                          You can make the action interactive to allow you a chance to move and resize the selection set by the plug-in while maintaing its aspect ratio by holding the shift key down during the interactive transform selection to constrand the transform to its current aspect ratio. That requites a fourth step you record a transform selection step that rotates the selection 180 degrees after the first step in the action before the crop step. After the action is recoeded you turn on the transform selection step's doialog to make the action interactive.

                           

                          The reason you rotated the selection 180 degrees is that you want to changes the selection not the area selected.  That way if the selection set by the script is acceptable all you need do is hit enter. If the action did not rotate the selection 180 degrees and the selection was acceptable and you hit enter that would cancel the transform and the action would stop at the transform step..

                           

                          That is also interresting for that means if you mess up while modifying the selection transform you can press ESC and stop the action in the transform selection step.  You can the click Play in the actions palette and retry doing the transform selection correctly.

                           

                          Message was edited by: JJMack

                           

                          Message was edited by: JJMack

                          • 10. Re: Cropping different file sizes script
                            JJMack CommunityMVP

                            Using the script to do the interactive Crop are requires one more action step then creating the interactive action without using the scripts. However two of the action steps need to be interactive where using the scrips onle the extra step needs to be interactive.

                             

                            The interactive action without scripting three steps.

                             

                            Step 1 rectangle marquee tool setetion mode set to ratio draged out a bit from uppet left corner

                            Step 2 Image>Crop

                            Step 3 Image Size resample not checked units set to inches

                             

                             

                            Step 1 and Step 3 dialog are turned on.

                             

                            This single action can be used to do every crop you need but requires more work for two steps require intervention. Also the interactive marquee tool  step is a pain to use. You  need to set in the aspect ratio for all crops other then to ratio user recording the step. And the selection always needs to be draged out and positioned.

                             

                            Step 3 is easy to use you just neet to enter one sid length for Photoshop to set the DPI. Sitt its a required second user interventioj.

                             

                            Still its only one three step action the can always be used.

                            • 11. Re: Cropping different file sizes script
                              ocphotog Community Member

                              I must be doing something wrong because I'm not getting the results I hoped for using your method. Here is what's happening.

                               

                              1. run script AspectRatioSelection - set it to 800x1000

                              2. marching ants show on image in correct aspect ratio.

                              3. If I rotate it 180 deg. it turns the selected image portion upside down.

                              3a. If I do Ctrl-T it reduces or enlarges the image, not the way I want to crop the image.

                              3b. If I have the Marquee tool selected I can move the marching ants up or down but nothing else.

                               

                              What I would like to do is to be able to adjust the selection in or out to change what will be cropped. Can't seem to do that with the marguee tool.

                               

                              Also, on the setting for the LongSidePrintLength. I'm assuming if I'm doing an 8x10 that I would make that setting 10?  I'm comfused when you say DPI, I'm thinking 300 dpi. so I think I'm supposed to have another step in the action to change the dpi to 300?

                               

                              What am I missing?

                               

                              Thanks!

                               

                               

                              Thanks!

                              • 12. Re: Cropping different file sizes script
                                ocphotog Community Member

                                You must have posted while I was composing my above questions since it showed up after I posted.

                                I've seem to come to the same conclusion though that using the marguee tool is not very efficient since although you can set it to aspect ratio you still might have to do it a few times to get the crop you like because you just can't grab a corner and move it like you can with the crop tool.

                                Seems like there is not a foolproof way to incorporate the crop tool as part of the action when different aspect ratios can come into play.

                                • 13. Re: Cropping different file sizes script
                                  ocphotog Community Member

                                  Ok, I just found your tool set "Image Visualization" and it had exactly what I was looking for ( 5x7 and 8x10 Interactive ) What I was doing wrong was using free transform instead of  Transform Selection.  Such a dummy I am some days. Those actions should work as I need.

                                   

                                  I appreciate all the help, and the scripts. Make me more productive for sure.

                                  • 14. Re: Cropping different file sizes script
                                    JJMack CommunityMVP

                                    ocphotog wrote:

                                     

                                     

                                    1. run script AspectRatioSelection - set it to 800x1000

                                    2. marching ants show on image in correct aspect ratio.

                                    3. If I rotate it 180 deg. it turns the selected image portion upside down.

                                    3a. If I do Ctrl-T it reduces or enlarges the image, not the way I want to crop the image.

                                    3b. If I have the Marquee tool selected I can move the marching ants up or down but nothing else.

                                    Here is the story:

                                     

                                    1. run script AspectRatioSelection - set it to 800x1000

                                    800 1000 is the same as 8 10 same as 4 5 same as 5 4

                                    its just a ratio not pixels you can enter the ratio any way you care to

                                    and the script figures which orintation to use Portrait or landscapt.

                                     

                                    2. marching ants show on image in correct aspect ratio

                                    yes the script figures the pixel sizes from top left and has an option to center using the correct orintation

                                     

                                    3. If I rotate it 180 deg. it turns the selected image portion upside down.

                                    You rotated the the pixels not the selection. Ctrl+t  rotates the area to rotate the selection use

                                    menu Select>Transform Selection

                                    • 15. Re: Cropping different file sizes script
                                      JJMack CommunityMVP

                                      I think you should read the text files in my crafting actions packege. I do not do text well but I work hard on those files. I tried to make them shortand packed full of good information.  They should make you think some ang give a lot of knowledge it took me years to fully understand.

                                       

                                      My Image Visulization package has an older version of AspectRatioSelection that does not have Path support I just added. I will Update the package.

                                      • 16. Re: Cropping different file sizes script
                                        ocphotog Community Member

                                        By gosh I think I got it.  I also added at the end of my action to set the resolution to 300. I often add a logo to the images and having different resolutions affected the size and placement of the logo. Setting it to 300 made it look the same on different size files.

                                        • 17. Re: Cropping different file sizes script
                                          ocphotog Community Member

                                          I've been reading through the wealth of info you have provided. I'm starting to understand it more each time. Thanks!

                                          • 18. Re: Cropping different file sizes script
                                            JJMack CommunityMVP

                                            300 DPI will work if you resample the image.  The  longsideprintlength will set the correct dpi resolution without resampling the document.

                                             

                                            In the crafting action package there is a sample watermarking action that can put a logo the correct size on any size image. The action dose this by using one of my utility scripts that is run twice. the first time it is run it records the document current dpi resolution. The action then changes the dpi resilution without resampling the image so it would print 8" wide. The action then placed in the logo the approate size for a 8" wide image and then positions the logo. The script is then run a second time the second time the script is run it retrieves the recorded dpi resolution and restores the document to that resolution. The net result is the image size is the same as it was to begin with and the logo has been sized to fit the images size.

                                            • 19. Re: Cropping different file sizes script
                                              JJMack CommunityMVP

                                              About the scripts in my crafting actions package.  All but the two Plug-in Scripts are small and should be easy to read.  You may gain a little knowledge if you read the source.  However remember I do not know javascript and object orientated programming. Once I was a programmer now I'm just a hacker. I fear if I did not hack some I would become senile.

                                              • 20. Re: Cropping different file sizes script
                                                ocphotog Community Member

                                                I wonder if it would fix my problem of my logo not landing in the same place depending on the image size and if vert or horizon.

                                                 

                                                What I do now is place the logo. It lands in the center of the document. I select all layers then move the logo to the bottom, then right using positioning buttons. Then I select only the logo layer. Then with the document rulers set to % I move the logo 5/8" up from the bottom and 5/8" left from the right.

                                                Looks good on an vert 8x10 for example but if I do it to an 10x8 I get a different result. Seems like it should work but it not.

                                                • 21. Re: Cropping different file sizes script
                                                  JJMack CommunityMVP

                                                  Use Photoshop to position your logo where you want. Its simple with align layers to selection.   For example you can simply to a select all then modify the selection to contract is some so it will not touch the canvas edges. With the logo the targeted layer using menu "layer>Align Layers to Selection>xxx"  twice you can position you logo as though you were putting in on a tick tack toe board within the selection. The selection need not be the whole document.  I use it to position text on Images and position images in collages. The images are position to the center of alpha channels that are loaded as selection and added as layer mask. The Layer mask acts like a virtual crop and the text can be placed over the image in one of nine places.

                                                  • 22. Re: Cropping different file sizes script
                                                    JJMack CommunityMVP

                                                    I hope your seeing the light. Use your eyes the see and read what features Photoshop has. Then use your brain when using Photoshop your brain now has the knowledge it need to do thing that would be inposible to do without the knowledge you have stored in it.

                                                     

                                                    I also do not think there is anything in this tread that is not in my crafting actions package.

                                                    Sample Actions.txt Photoshop CraftedActions set saved as a text file.