12 Replies Latest reply on Oct 8, 2015 7:02 AM by JJMack

    Cropping script help

    hardy11111

      I need a script to crop any images to this size 3000 x 2247 at 72 DPi can any one help me out please

        • 1. Re: Cropping script help
          nvkzNemo Level 2

          What are you mean by "any images"? All layers from current document or all images from folder?

           

          And whats happened after cropping?

          • 2. Re: Cropping script help
            hardy11111 Level 1

            After cropping image size will be 3000 x 2247 at 72 DPi . Ex. if the image size is 5400 X 4500 with 300dpi after running the script it changes to 3000 x 2247 at 72 DPi .. this is what i wanted buddy.

            • 3. Re: Cropping script help
              nvkzNemo Level 2
              resizeAndCrop(3000, 2247);
              
              function resizeAndCrop(newWidth, newHeight) {
                  var doc = app.activeDocument,
                      originalRulerUnits = preferences.rulerUnits;
              
                  preferences.rulerUnits = Units.PIXELS;
              
                  var docW = doc.width.value,
                      docH = doc.height.value;
              
                  resizeImage();
                  resizeCanvas();
              
                  // Image Size
                  function resizeImage() {
                      var desc1 = new ActionDescriptor();
                      if (docW < docH) {
                          desc1.putUnitDouble(charIDToTypeID('Wdth'), charIDToTypeID('#Pxl'), newWidth);
                      } else {
                          desc1.putUnitDouble(charIDToTypeID('Hght'), charIDToTypeID('#Pxl'), newHeight);
                      }
                      desc1.putUnitDouble(charIDToTypeID('Rslt'), charIDToTypeID('#Rsl'), 72);
                      desc1.putBoolean(stringIDToTypeID("scaleStyles"), true);
                      desc1.putBoolean(charIDToTypeID('CnsP'), true);
                      desc1.putEnumerated(charIDToTypeID('Intr'), charIDToTypeID('Intp'), stringIDToTypeID("automaticInterpolation"));
                      executeAction(stringIDToTypeID('imageSize'), desc1, DialogModes.NO);
                  }
              
                  // Canvas Size
                  function resizeCanvas() {
                      var desc1 = new ActionDescriptor();
                      if (docW < docH) {
                          desc1.putUnitDouble(charIDToTypeID('Hght'), charIDToTypeID('#Pxl'), newHeight);
                      } else {
                          desc1.putUnitDouble(charIDToTypeID('Wdth'), charIDToTypeID('#Pxl'), newWidth);
                      }
                      desc1.putEnumerated(charIDToTypeID('Vrtc'), charIDToTypeID('VrtL'), charIDToTypeID('Cntr'));
                      desc1.putEnumerated(charIDToTypeID('Hrzn'), charIDToTypeID('HrzL'), charIDToTypeID('Cntr'));
                      desc1.putEnumerated(stringIDToTypeID("canvasExtensionColorType"), stringIDToTypeID("canvasExtensionColorType"), charIDToTypeID('BckC'));
                      executeAction(stringIDToTypeID('canvasSize'), desc1, DialogModes.NO);
                  }
                  preferences.rulerUnits = originalRulerUnits;
              }
              
              
              
              

               

              or just crop

               

              resizeCanvas(3000, 2247);
              
              function resizeCanvas(newWidth, newHeight) {
                  var desc1 = new ActionDescriptor();
                  desc1.putUnitDouble(charIDToTypeID('Wdth'), charIDToTypeID('#Pxl'), newWidth);
                  desc1.putUnitDouble(charIDToTypeID('Hght'), charIDToTypeID('#Pxl'), newHeight);
                  desc1.putEnumerated(charIDToTypeID('Vrtc'), charIDToTypeID('VrtL'), charIDToTypeID('Cntr'));
                  desc1.putEnumerated(charIDToTypeID('Hrzn'), charIDToTypeID('HrzL'), charIDToTypeID('Cntr'));
                  desc1.putEnumerated(stringIDToTypeID("canvasExtensionColorType"), stringIDToTypeID("canvasExtensionColorType"), charIDToTypeID('BckC'));
                  executeAction(stringIDToTypeID('canvasSize'), desc1, DialogModes.NO);
              }
              
              • 4. Re: Cropping script help
                hardy11111 Level 1

                I have alignment to add in this will get back to you buddy much appreciated thanks for your help mate.

                • 5. Re: Cropping script help
                  JJMack Most Valuable Participant

                  hardy11111 wrote:

                   

                  After cropping image size will be 3000 x 2247 at 72 DPi . Ex. if the image size is 5400 X 4500 with 300dpi after running the script it changes to 3000 x 2247 at 72 DPi .. this is what i wanted buddy.

                  Of the 5400x4500 pixels which pixels do you want cropped off. Or do you want the image resized to fit within the 300x2247 pixels area so it composition does not change then add pixels to the resize image to add borders. the add the missing pixels.

                   

                  If the later a simple action will do the trick

                  Step 1 Automate Fit Image 3000 width 2247 height

                  Step 2 Canvas size 3000 width 2247 height

                  Step 3 Image size resample not checked set dpi to 72.

                  • 6. Re: Cropping script help
                    hardy11111 Level 1

                    Hey JJMack the images which have to resize has an size of 2175 x 2850 with 300 dpi .. i need those images to be resized with the size of 3000 x 2247 with 72 dpi with center alignment

                    • 7. Re: Cropping script help
                      hardy11111 Level 1

                      Hey nvkz Nemo the images which have to resize has an size of 2175 x 2850 with 300 dpi .. i need those images to be resized with the size of 3000 x 2247 with 72 dpi with center alignment

                      • 8. Re: Cropping script help
                        nvkzNemo Level 2

                        I don't very well understand you.

                         

                        hardy11111 the code in the my previous post resize and crop any images to 3000 x 2247 (72 dpi).

                         

                        If you are need only resize you can use File > Automate > Fit Image

                        • 9. Re: Cropping script help
                          hardy11111 Level 1

                          resizing is fine nemo .. can you add a code which center align the image ?

                          • 10. Re: Cropping script help
                            hardy11111 Level 1

                            hi nemo can you contact me via skype  or gmail ? yogeshwaran1991@gmail.com skyp id = yogeshwaran1991

                            • 11. Re: Cropping script help
                              hardy11111 Level 1

                              hi nemo can you contact me via skype  or gmail ? yogeshwaran1991@gmail.com skyp id = yogeshwaran1991

                              • 12. Re: Cropping script help
                                JJMack Most Valuable Participant

                                hardy11111 wrote:

                                 

                                Hey JJMack the images which have to resize has an size of 2175 x 2850 with 300 dpi .. i need those images to be resized with the size of 3000 x 2247 with 72 dpi with center alignment

                                In that case you are putting a portrait aspect ratio image onto a Lanscape canvas. There will be big boarders on both sides.  Your 2175x2850 images will be downsized to 1715x2247 and then 642.5pixel wide canvas borders will be added to the left and right sides.  The action I described will do that and it can be batched.

                                Capture.jpg