# PHP - Fitting an Image into a Canvas

**URL:** <https://forum.kirupa.com/t/php-fitting-an-image-into-a-canvas/217592>\
**Category:** programming\
**Created:** [February 28, 2007, 4:29am UTC](https://forum.kirupa.com/t/php-fitting-an-image-into-a-canvas/217592 "2007-02-28T04:29:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nineteen](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nineteen/32/2679_2.png) [@Nineteen](https://forum.kirupa.com/u/Nineteen)\
**Post date:** [February 28, 2007, 4:29am UTC](https://forum.kirupa.com/t/php-fitting-an-image-into-a-canvas/217592/1 "2007-02-28T04:29:33Z")

</div>

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.
