0

I am using nodejs packages (imagemagick and graphicsmagick) for image resize and image crop. But how to resize all the images in the particular folder to another folder.

For example I am trying to convert all images in test folder to resize test1 folder.

var fs = require('fs'), gm = require('gm');

 gm('test/abcd.jpg').resizeExact(240, 240).write('test1/abcd.jpg', function(err) {
 if (err) {
 console.log(err);
 } else {
 console.log('done');
 }
 });

Anyone help for this.

Sebas
  • 21,192
  • 9
  • 55
  • 109
RSKMR
  • 1,812
  • 5
  • 32
  • 73
  • did you find a solution to this? i need to convert all jpegs in one folder and save it to another folder as well. I have 100's of images – jasan Sep 01 '17 at 11:05

1 Answers1

0

The normal way to iterate through a directory of files with ImageMagick is to use the mogrify command like this:

mogrify -path resized -resize 1000x1000 *.png

which will take all the PNG files in the current directory and resize them and write the results into a subdirectory called resized.

I am no expert on nodejs but I don't believe the mogrify command exists in the port. There is a thing called cadabra but it looks old and disused to me - again I may be wrong. Link is here.

Else, you will need to walk the directory... like this.

Community
  • 1
  • 1
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432