Skip to main content
Participating Frequently
September 12, 2017
Answered

Resizing script with different sizing for every image

  • September 12, 2017
  • 3 replies
  • 4874 views

Hi all,

I currently have a large number of png files that are for web use. For our website each image needs to be at a 1:1 ratio and cropped. For the cropping part of the script I just batched all of the images using the trim function. This leaves me with a ton of images with different widths and heights. Is it possible to run a resizing script that will match the larger dimension of each image whether it be the height or width so everything will be at a 1:1 ratio?

Thanks for the help

This topic has been closed for replies.
Correct answer Chuck Uebele

Thanks again for the constant help guys. I will try again. Does it matter that all the images that I am using are pngs possible causing that script to freeze up? I will try and explain again simply what I am trying to do (if that helps at all).

1. I have a bunch of pngs with a transparent background in a folder.

2. My first action is to Select Image > Trim and take the top left pixel colour. This is what we have been doing to crop the images.

3. My next action which is causing this discussion is to match the highest dimension whether it be the height or width.

4. Save the resulting image in a new folder and move on to the next.

Sorry again if I am not giving the best of details. I am fairly new with photoshop and am working on a massive overhaul of images in a catalogue.

Everything is much appreciated.


It should work with pngs. So according to your last post, it looks like you're trimming rather than "cropping." So you don't actually want to crop into the image. Then you want the image to be a 1:1 aspect ratio, so that would mean increasing the canvas size, rather than resizing the image to the longest dimension. Is that right? If so, try this script. All is does is resize the canvas.

#target photoshop

app.preferences.rulerUnits = Units.PIXELS;

var doc = activeDocument;

var lSide = parseInt(Math.max(doc.width,doc.height));

canSize ();

function canSize (){

    var idCnvS = charIDToTypeID( "CnvS" );

        var desc11 = new ActionDescriptor();

        var idWdth = charIDToTypeID( "Wdth" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc11.putUnitDouble( idWdth, idPxl, lSide );

        var idHght = charIDToTypeID( "Hght" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc11.putUnitDouble( idHght, idPxl, lSide );

        var idHrzn = charIDToTypeID( "Hrzn" );

        var idHrzL = charIDToTypeID( "HrzL" );

        var idCntr = charIDToTypeID( "Cntr" );

        desc11.putEnumerated( idHrzn, idHrzL, idCntr );

        var idVrtc = charIDToTypeID( "Vrtc" );

        var idVrtL = charIDToTypeID( "VrtL" );

        var idCntr = charIDToTypeID( "Cntr" );

        desc11.putEnumerated( idVrtc, idVrtL, idCntr );

    executeAction( idCnvS, desc11, DialogModes.NO );

    }

3 replies

Participating Frequently
October 3, 2017

Still looking for any suggestions on this. Another quick example of what I am trying to do is I have an image that is 4000Wx3000H and a second one that is 3200Wx3900H. What I am hoping a script can do is trim the pngs, and then resize to 4000WX4000H and 3900WX3900H. After the trim the dimensions will change, but basically I want to match what is bigger, whether is be the height or width.

Thanks

JJMack
Community Expert
Community Expert
October 3, 2017

two step action

Step 1 Aspect Ratio selection  1 1 center rectangle replace selection

Step 2 Image Crop

Action can be batched....

JJMack
Participating Frequently
October 3, 2017

Hey JJ, how do you get to the aspect ratio selection screen? Thanks for the help, kind of a noob at this stuff and trying to figure it out.

Jarda Bereza
Inspiring
September 13, 2017

Regular crop tool can have specified widht and height... so it will crop and resize your image in one step.

Chuck Uebele
Community Expert
Community Expert
September 12, 2017

Yes, that can be done, but if you want the 1:1 ratio, you really need to manually crop, or you really don't know where the image will be cropped, unless you don't mind distorted images. Image Processor will resize image to a max size.

Participating Frequently
September 12, 2017

I am actually resizing the canvas to 1:1 after trimming so its the canvas that I need at a 1:1 processor so the image won't get distorted as you said. Can image processor resize the canvas to a max size as well?

Chuck Uebele
Community Expert
Community Expert
September 12, 2017

Image processor will resize the longest side image to whatever you put in the field to resize it to.