节点画布:调整图像大小

时间:2018-10-05 14:08:14

标签: node.js node-canvas

是否有一种调整图像大小的方法?我有以下代码:

fs.readFile('./model/pic.jpg', (err, data) => {
    img = new Image;
    img.src = data;

    if (img.width > img.height) {
        img.height = 224;
    } else {
        img.width = 224;
    }

    const canvas = new Canvas(img.width, img.height);
    const ctx = canvas.getContext('2d');

    ctx.drawImage(img, 0, 0, img.width / 4, img.height / 4);
})

但是图像以及画布的原始尺寸仍然为500x375。

有什么想法吗?

0 个答案:

没有答案
相关问题