Convert odd-sized images to square dimensions?

etherealfocus

Senior member
Jun 2, 2009
488
13
81
I've got a catalog of about 30k product images at work of all sizes and aspect ratios. I need them all to be square (width equal to height) so they don't get distorted on our webcart (which stupidly requires square images; support tells us there's no easy way to preserve aspect ratio since the entire cart is kind of a hack job). The images are all different sizes so I can't just add x to the width or whatever.

Essentially I need (width=width+x) where x=height-width

Can't find an appropriate batch processing option in Fireworks or FastStone Photo Resizer. Any ideas?
 

KingFatty

Diamond Member
Dec 29, 2010
3,034
1
81
Irfanview has lots of batch image adjustment options, might be able to set up something like this as a batch resize function?
 

Leros

Lifer
Jul 11, 2004
21,867
7
81
You shouldn't resize them disproportionally.

Resize them such that they're the width of the square image size, then put them onto a black square background.
 

etherealfocus

Senior member
Jun 2, 2009
488
13
81
Thing is, we get images from a zillion different vendors, most of whom are abysmally low tech. Some of the images are professionally shot and 1-3MPixels, others are literally taken on some dude's cameraphone and I have to cut them down to like 400x300 or they're just a pixely mess. We want to preserve the good quality hi res images especially since they tend to be for our better products... so the big catches are 1. that I can't use a single width or height because of the high variance in image size and quality and 2. that I need to convert rectangular aspect ratios to square without distortion.
 

Leros

Lifer
Jul 11, 2004
21,867
7
81
Pretending the final size is 100px100px.

To generate the largest image possible while preserving the original proportions, do something like this:
Code:
if (original_width > original_height) {
   // resize so that resized_width = 100px;
} else {
   // resize so that resized_height = 100px;
}
// put resized image centered onto a 100px100px black square

Should be fairly easy to write a script to do something like that for an arbitrary image. Then you can just run that script on your zillions of images.
 

KingFatty

Diamond Member
Dec 29, 2010
3,034
1
81
OK I think you can definitely use Irfanview to batch convert any number of files.

I'll also pretend you want 100x100 px images.

The trick is that Irfanview can automatically find your "long" dimension of the image (height or width). Then you would simply make sure the longest side of the image fits in the 100 pixel size.

Then, the 2nd part, is that you want the canvas size to be 100x100 pixels or whatever square size.

So if you have a wide and short image, it would reduce the wide part to fit, then enlarge the canvas size to make a square image. Same for tall narrow images, it would reduce the height to fit, then enlarge the canvas size to make a square image.

So, you won't get distortion, just all square images where the canvas is enlarged to compensate.

Check out the various settings in the screenshot I took. It's under file-batch convert:

Clipboard01.jpg