Created
July 18, 2016 09:07
-
-
Save quangnd/de08fa883348e157531f7792afd02cce to your computer and use it in GitHub Desktop.
Resize image with gm module
This file contains hidden or 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
var fs = require('fs'), | |
gm = require('gm').subClass({imageMagick: true});; | |
var IMAGE_DIR = __dirname +'/images/', | |
SAVE_DIR = __dirname +'/imagesResize/'; | |
var imageList = ['1.jpg', '2.jpg', '3.jpg']; | |
var resize_keep_ratio = function(name) { | |
console.log(IMAGE_DIR+ name); | |
gm(IMAGE_DIR+ name) | |
.resize(200,200,'^') | |
.gravity('Center') | |
.extent(200, 200) | |
.write(SAVE_DIR+name, function(err) { | |
if (err) console.log(err); | |
console.log(SAVE_DIR+name); | |
}); | |
} | |
imageList.forEach(function(img) { | |
resize_keep_ratio(img); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment