Skip to content

Instantly share code, notes, and snippets.

@Ugarz
Last active July 31, 2017 10:46
Show Gist options
  • Save Ugarz/55516bbdcc8a4eabce102f6c638f0904 to your computer and use it in GitHub Desktop.
Save Ugarz/55516bbdcc8a4eabce102f6c638f0904 to your computer and use it in GitHub Desktop.
Resize an image with the gm library, quick'n'easy

Simple image resizer with node

For more api, see here

const fs = require('fs');
const gm = require('gm');

gm('id.jpg')
.toBuffer('JPG', function (err, buffer) {
    if (err) return console.error(err);
    var base64data = new Buffer(buffer).toString('base64');
    // Do whatever you want with the buffer, like a SOAPY and Fun request
    console.log('base64data', base64data);
})
.thumb(350,350, 'thumbnail.jpg', 100, () => console.log('Tumbnail ready'))
.resize(110, 110)//max width
// Write resized image
.write('./resized.png', function (err) {
  if (!err) console.log('done');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment