P
P
Pavel Gogolinsky2015-10-01 22:40:55
Yii
Pavel Gogolinsky, 2015-10-01 22:40:55

How do you preview an image when you can't crop the photo?

The original image is the store's logo of arbitrary size and orientation. It is necessary to change the image before saving: make it square, 150x150 in size. You can't crop a photo. It should be taken into account that the original image can be large (1024x768) and small (100x20). If it is too small, you need to fit the logo in the center into a 150x150 square.
Who carried out such a task? Prompt with a solution.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cat Anton, 2015-10-01
@gogolinsky

You can't turn 1024x768 into 150x150 without cropping or deforming it: by stretching it in height and then reducing it.
And if the image is a photograph, i.e. the background is not initially white, then there will be white stripes off topic.
In any case, if the white stripes suit you, take ImageMagick in your hands and go:
1. Get the height and width of the original image;
2. If the width is greater than the height, then proportionally reduce to 150px in width, otherwise - to 150px in height;
3. Overlay the resulting image in the center on the image of a white square 150x150
But it's better to use JavaScript like fengyuanchen.github.io/cropper and let the user choose the square area of ​​the image. As a result, the previews will turn out beautiful, correctly positioned and without any white stripes along the edges.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question