简体   繁体   English

节点画布图像处理

[英]node-canvas image manipulation

I'm trying to resize and crop an image in node.js我正在尝试调整和裁剪 node.js 中的图像

I've been using graphicsmagick:我一直在使用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?我不知道如何使用 canvas,canvas 中的等价物是什么?

Thanks.谢谢。

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 img = 图像元素
  • sx = source x sx = 源 x
  • sy = source y sy = 源 y
  • sw = source width sw = 源宽度
  • sh = source height sh = 源高度
  • dx = destination x dx = 目的地 x
  • dy = destination y dy = 目的地 y
  • dw = destination width dw = 目标宽度
  • dh = destination height dh = 目标高度

Crop using sx, sy, sw, sh使用 sx、sy、sw、sh 进行裁剪

Resize using dw, dh使用 dw、dh 调整大小

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM