Created
August 24, 2017 13:30
-
-
Save abinavseelan/9f070a03633173a45761a6ced0ec9e20 to your computer and use it in GitHub Desktop.
Medium - Image Manipulation using NodeJS - Resize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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