crop-img
Creates a crop region with the given dimensions and alignment to be used with HTML canvas drawImage
, similar to background-size: cover
/ object-fit: cover
.
Install
npm install crop-img
Use
; const width = windowinnerWidth;const height = windowinnerHeight; const context = document;contextcanvaswidth = width;contextcanvasheight = height;documentbody; const img = ;imgcrossOrigin = 'anonymous';imgsrc = 'https://source.unsplash.com/random/1600x900';imgonload = onload; { // returns and object with x, y, width and height properties const rect = ; context;}