I have a list of images with text wrapped around but images I receive come in different sizes (all larger than 150px). I need to crop them all to 150x100px but keep correct aspect ratio. Could anyone please suggest the best way of solving this problem? Thanks!
HTML:
<ul>
<div class="post" id="post">
<div>
<li>
<img class="TextWrap" src="{{ picture }}">
<a href="{{ link }}">{{ message }}</a><p>
{{ time }}
</li>
</div>
</ul>
CSS:
.post {
width: 500px;
margin-top: 15px;
float: left;
}
.post img {
width: 150px;
height: 100px;
margin-bottom: 15px;
margin-right: 20px;
}
.TextWrap {
float: left;
}
Cropping is the process of removing a portion of an image in order to improve framing, emphasize a subject, or change the aspect ratio. This type of photo editing allows you to keep all of the elements you want while removing those you don't.
Simply left-click on the image to select it. Then set “ Lock aspect ratio” to true in the Properties window. You can also preserve the aspect ratio by pressing the Ctrl-key while resizing a shape. Let's now have a look at an example to get a better understanding.
One way to do this is to use a program like Photoshop. With Photoshop, you can resize an image without losing quality by using the "Image Size" dialog box. In the "Image Size" dialog box, you can change the width and height of the image. You can also change the resolution.
As long as you do not want server side cropping, you can add following css:
.post img {
object-fit: cover;
}
Please check more possible values for object-fit
As an alternative to Ray's answer, you can set the images as backgrounds and use:
background-size: cover;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With