“Resize Image failed to evaluate height”

Hello,

I am trying to make a macro that resizes a batch of images in a folder to be width RAND(493,929).

Currently, when I run the macro I get the error “Resize Image failed to evaluate height”.

However, I do not want to change the ratio of the images and so therefore don't know what to put into the Height field of the “Resize Image” action.

How can I alter the width of these images so that their height is automatically adjusted in accordance with the width in such a way that it doesn't squash or stretch the image?

I've attached my failed macro below.

05

Thank you,
Chris

Hi Chris,

The height field is currently blank, which is why it's failing to evaluate the height. My suggestion is to set the width as a randomly determined variable and the height as the ratio you want of that variable, then use those variables in the resize image fields. Here's an example to get you started; if all works as planned, you should just need to tweak the output path and the height ratio to get what you want.

Resize All Images in Folder.kmmacros (6.0 KB)

Thank you for your time gglick, setting it to a variable is a good suggestion and start.

One issue I can envision with that though is that the image width to height ratio can be different from one image to the next, and so the multiplier 1.33 would still squash/stretch some images in the folder.

Any idea how to get around that?
Chris

Okay, now that I've had more time to think about and experiment with this, I believe this will do the trick better:

Resize All Images in Folder 1.1.kmmacros (9.6 KB)

This macro should

  • Look at all the files in the folder set in the initial For Each action
  • Read the ones that are images to a named clipboard (Image Clipboard by default)
  • Divide each image's width by its height to get that image's exact ratio
  • Use that ratio to set the image's height against the randomly determined width
  • Write the resized file with a suffix ("_Resized" by default) as either a PNG or JPEG depending on the original file's format
  • Display a notification when all files have been resized

If you need it to account for more or different file formats, you can change that in the Switch/Case action near the bottom; hopefully it's self-explanatory enough to figure out how to do that on your own.

Hi @gglick

Sorry for the slow reply. Just wanted to say I've been using this macro for the last few days and it works perfectly.

A great asset to have in my macro library!

Thank you so much for taking the time to help me with this.

Chris

Glad to hear it! I don't typically have a reason to work with images, especially ones that need to be randomly resized, so this was a fun exercise for me too.