0
votes

Php thumb resize image based on provided width and height, I am working on profile image which is: 130x130

While users are uploading image of long heights(rectangle) which leads to strecthed image in its width and when uploading long width image(rectangle) then strecthed, I hope you understand what I mean. Because when anyone uses a large square image it resize to correct 130x130 but longer width and height get strecthed.

I am thinking of having a good suggestion or idea to work around such images, either crop them from top to make them perfect square first.

Thanks, Najm.

1
Do you want to display cropped images / images of size 130 x 130 only???Php Geek
The easiest solution is to just require the user to submit a square or squarish (then squeeze) picture. Because you never know what they want to clip. If you're in for some work you can build something that allows them to pick the portion if it's not a square. I'm sure there are APIs that make this easier, or you can use something like en.gravatar.comRaekye
You can give your users the functionality to crop your image after it has been uploaded. When cropping, make it so that the height and width are maintained in a 1:1 ratio.Charles

1 Answers

1
votes

Usually you will take the longer side, scale it up and scale the shorter side by the same percentage. One such snippet is here. You can also prefill the canvas with a smooth background that fits with your overall design.