Resize Selected Images

This macro will resize images selected in the finder to an approximate target size in MB, if their original size exceeds it.

I'm no mathematician, but I've tested this with images of original size up to 50MB, and the results are close enough to the target size for most uses. If anyone can think of a way to make the resizing calculation more accurate, please comment below.

Resize Finder Image.kmmacros (62.3 KB)

Macro Screenshot


Notes on the maths:

My theory was to equate the area (number of pixels) to the filesize. Then by using geometry, to calculate the ratio by which to multiply the height and width.

Height2 = Height1 x √(Area2 ÷ Area1)
Width2 = Width1 x √(Area2 ÷ Area1)

Say we have a H20 x W30 rectangle. The area is 600. If we want the new area to be 180, then we would do this:

New Height = 20 x √(180 ÷ 600) = ~10.95
New Width = 30 x √(180 ÷ 600) = ~16.43

Check new area: ~10.95 x ~16.43 = ~180

When I do this in the macro, the result is higher than it should be. To account for this, I multiply TargetMB by 0.85 at the start of the calculation; this gets us close enough.

2 Likes