Node.js: image resizing without ImageMagick

前端 未结 12 1675
离开以前
离开以前 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:26

    I have recently started developing an image processing module for NodeJS without any runtime dependencies (read why). It's still at early stages, but already usable.

    What you are asking for would be done as follows:

    image.resize(200, 200, function(err, image){
        // encode resized image to jpeg and get a Buffer object
        image.toBuffer('jpg', function(err, buffer){
            // save buffer to disk / send over network / etc.
        });
    });
    

    More info at the module's Github repo.

提交回复
热议问题