U
U
Username2016-05-04 18:55:15
css
Username, 2016-05-04 18:55:15

How to scale down an image without changing the aspect ratio?

How can I reduce the width of an image by 50px, without changing the proportions, and so that everything fits into a circle (not flattened or stretched out)?
Figure 1 uses bootstrap rounding and sets the property width = 50 px

<img src="http://fxstock.ru/uploads/2013-03/1362253286_Novym-anfas-aromata-Chane.jpg" width="50px"  class="img-circle">

ebdbcffdb00c484e956b1319d4f0ae16.png
Figure 2 uses bootstrap rounding and sets the properties width = 50 px, height = 50 px
<img src="http://fxstock.ru/uploads/2013-03/1362253286_Novym-anfas-aromata-Chane.jpg" width="50px" height="50px"  class="img-circle">

ecbfd00a890f48ef8d81a821fb145e9f.png
It turns out the following algorithm:
1. We reduce the image proportionally in width to 50px
2. If the height is less than the width, then we reduce the height to 50px, respectively, the width will be greater than
3. The image is centered
All this allows you to make a background, but you need to use the img tag.
I found a similar question on the toaster, but it does not take into account the algorithm that I gave above and therefore the chopped edges.
How to properly resize images with CSS/HTML?
22157b3cf1a14d889aa74f1da82d8ae7.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Milok Murlyka, 2016-05-04
@dalv_happy

codepen.io/anon/pen/RaEoEP

D
Dima Pautov, 2016-05-04
@bootd

Proportions only:
1) background through background-size: cover
2) new property object-fit
3) as well as cropping on the server

P
profesor08, 2016-05-04
@profesor08

Here are the options, which one to use decide:
codepen.io/Profesor08/pen/grZgjX

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question