CCalclabhub

Work

The scale factor

Both dimensions have to be multiplied by one number, so the box can only be met on one axis. Fitting inside chooses the smaller ratio and leaves a gap on the other axis, filling chooses the larger and crops the overflow.

The Formula

fitting inside: s = min(W / w, H / h); filling and cropping: s = max(W / w, H / h)

Both dimensions have to be multiplied by one number, so the box can only be met on one axis. Fitting inside chooses the smaller ratio and leaves a gap on the other axis, filling chooses the larger and crops the overflow.

SymbolMeaning
wSource width
hSource height
WBox width
HBox height
sScale factor

What Each Symbol Means

wpixels

Source width

Pixels across the original image.

hpixels

Source height

Pixels down the original image.

Wpixels

Box width

Pixels across the target the platform asks for.

Hpixels

Box height

Pixels down the target the platform asks for.

sratio

Scale factor

The single number both dimensions are multiplied by.

See It Worked With Real Numbers

A formula on its own does not tell you which number goes where. The how to resize product images page applies this equation to a concrete case, shows every intermediate step, and names the mistakes that produce a wrong answer even when the algebra is right.

Where This Formula Appears

This equation is the working core of How To Resize Product Images, filed under Everyday Life. Every number the guide produces comes from substituting into this one line.