PHP - Fitting an Image into a Canvas

Hey there,

I have been working on a shopping cart and for design purposes each image needs to be the same width/height.

If the user it to upload a very tall image, then it becomes widened and stretched and ruins the look of the product as well as the website design.

Is there a possible way with PHP to create an image canvas with a white background, set it’s width/height…
Take the uploaded image, constrain to the greatest width or height proportionally…
Then fit this image into the centre of the dynamically generated canvas and save it as a new file.

Effectively… Resizing the image proportionally to fit in the centre of the constrained canvas and saving it as a new image.