Wideimage resize constraint from height?

I am trying to make an resize script with the use of wideimage. But I want to resize the image if its landscape to 125 px height or if its potrait to 125 wide… How do I do so? Here is what I got now:

$img = WideImage::loadFromFile($_FILES['file']['tmp_name']);
		
$img = $img->resize(125);
		
$img->saveToFile('profileimages/' . $file);
		
$cropped = $img->crop('center', 'center', 125, 125);
		
$cropped->saveToFile('profileimages/' . $file);

I want to make my images exactly 125 px square without any empty spaces.

Any ideas anyone?

Thanks in advance…

what is the name of your form field for the file?

file

$img = WideImage::loadFromFile($_FILES['file']['tmp_name'])->resize(125 , 124 , 'outside')->crop('center', 'center', 125, 125)->saveToFile('yourfile path');