1.0.0 • Published 10 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-canvasUsage
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)
imgan<img>elementxthe distance along the x axis to begin croppingythe distance along the y axis to begin croppingwidththe width of the section you want to cropheightthe height of the section you want to cropscaleWidthscale the final image up/down to this width (optional - defaults towidth)scaleHeightscale 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
10 years ago