Node.js: image resizing without ImageMagick

前端 未结 12 1655
离开以前
离开以前 2020-12-22 18:56

I\'m developing a web app on Node.js (+ express 4) where users can set their profile image by uploading it to the server. We already limit the file mimetype and max filesize

12条回答
  •  滥情空心
    2020-12-22 19:19

    I like resize-img library for its simplicity.

    const fs = require('fs');
    const resizeImg = require('resize-img');
    
    (async () => {
        const image = fs.readFileSync('unicorn.png');
    
        const newImage = await resizeImg(image, { width: 128, height: 128 });
    
        fs.writeFileSync('unicorn-128x128.png', newImage);
    })();
    

提交回复
热议问题