1.0.0 • Published 8 years ago
@f/img-to-canvas v1.0.0
img-to-canvas
Convert an img tag into a canvas tag, optionally with clipped dimensions (works only in browser).
Installation
$ npm install @f/img-to-canvas
Usage
var toBlob = require('@f/dataurl-to-blob')
var toCanvas = require('@f/img-to-canvas')
function cropImage (img, x, y, width, height) {
return toBlob(toCanvas(img, x, y, width, height).toDataURL('image/png'))
}
Returns a canvas element containing the cropped image.
API
imgToCanvas(arg)
img
an<img>
elementx
the distance along the x axis to begin croppingy
the distance along the y axis to begin croppingwidth
the width of the section you want to cropheight
the height of the section you want to cropscaleWidth
scale the final image up/down to this width (optional - defaults towidth
)scaleHeight
scale the final image up/down to this height (optional - defaults toheight
)
Returns: A canvas element containing the image at the specified dimensions.
License
MIT
1.0.0
8 years ago