Skip to content

Instantly share code, notes, and snippets.

@abinavseelan
Created August 24, 2017 13:30
Show Gist options
  • Save abinavseelan/9f070a03633173a45761a6ced0ec9e20 to your computer and use it in GitHub Desktop.
Save abinavseelan/9f070a03633173a45761a6ced0ec9e20 to your computer and use it in GitHub Desktop.
Medium - Image Manipulation using NodeJS - Resize
const gm = require('gm');
const width = 200;
const height = 50;
gm('/path/to/image/file')
.resize(width, null) // This will resize the width while maintaining the aspect ratio
.write('/path/to/output', (err) => {
if (err) {
console.log(err);
}
})
gm('/path/to/image/file')
.resize(null, height) // This will resize the height while maintaining the aspect ratio
.write('/path/to/output', (err) => {
if (err) {
console.log(err);
}
})
gm('/path/to/image/file')
.resize(width, height) // This will break the aspect ratio and resize width AND height
.write('/path/to/output', (err) => {
if (err) {
console.log(err);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment