Fit aspect ratio button on canvases

It would be great if there was a fit aspect ratio button on canvases that can take the currently loaded image and resize the X and Y values to fit.
It’s quite simple really. If X is less than Y it will be X / Y, otherwise Y / X.
It’s so tedious to calculate every aspect ratio for all my canvas items.