I have a large number of variable size images that may either be uploaded or found in a database. Without running a script to do the resizing, is there any way to purely modify the HTML or use CSS so that instead of having the image distorted and stretched out to match my allocated dimensions of 300×200, I instead have a 300×200 image cut of out my originally large picture (say for example 400×400)?
My current markup looks like
<image data-src="holder.js/300x200" alt="300x200" style="width:300px; height:200px;" src={{ photo.source_descr }}>
If I understood your question correctly, you want to resize the image using CSS/HTML with
heightandwidthwithout stretching the image. You want to crop it instead.I’m pretty sure that you’re looking for the
clipproperty in CSS. Mixclipandwidthandheightto crop your image so that it isn’t stretched, yet cropped to fit the desiredwidthandheight. Read up more aboutcliphere.Here is the extra code you requested for your needs (note that it uses jQuery, so you need that embedded for this to work):
Note that I got the second script from this question: Cropping images from center on the fly.