Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crop a picture with Javascript or CSS?

I have pictures of constant width (i.e. 100px) but with variable height (could be 200px, 130px, ... but height is always >= 100px).

I'm looking for CSS or JavaScript code that can crop the bottom of the picture so that all my pictures will be of size 100x100.

Can this be done, or should I use some PHP (or other server side language) library?

like image 598
Anna Fr. Avatar asked Mar 17 '26 21:03

Anna Fr.


2 Answers

HTML:

<div id="cutter">
  <img src="..." alt=""/>
</div>

CSS:

div#cutter {
  overflow: hidden;
  width: 100px;
  height: 100px;
}
like image 144
KARASZI István Avatar answered Mar 20 '26 11:03

KARASZI István


Yes, this can be done using CSS. For example :

<div style="background-image:url('stuff.png');width:100px;height:130px;"></div>
like image 42
slaphappy Avatar answered Mar 20 '26 11:03

slaphappy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!