Search code examples
javascriptcanvasnode.jsgraphicsmagick

node-canvas image manipulation


I'm trying to resize and crop an image in node.js

I've been using graphicsmagick:

code is as follows:

gm(path)
.resize(width, height)
.crop(50, 50, left, top)
.write(path, function(err){})

It's very simple. I have no idea how to use canvas, what's the equivalent in canvas?

Thanks.


Solution

  • For some reason, this signature is never used in examples:

    context.drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh);
    
    • img = the image element
    • sx = source x
    • sy = source y
    • sw = source width
    • sh = source height
    • dx = destination x
    • dy = destination y
    • dw = destination width
    • dh = destination height

    Crop using sx, sy, sw, sh

    Resize using dw, dh