Skip to content

Instantly share code, notes, and snippets.

@fdaciuk
Created July 17, 2014 11:24
Show Gist options
  • Save fdaciuk/3259432900a54b25f6e8 to your computer and use it in GitHub Desktop.
Save fdaciuk/3259432900a54b25f6e8 to your computer and use it in GitHub Desktop.
Tratamento de imagens com NodeJS

Tratar imagens com NodeJS

Dependências:

Instalação do Imagemagick no Ubuntu: apt-get install imagemagick

var fs = require( 'fs' );
var gm = require( 'gm' );
var imagesSrc = __dirname + '/images';
var imagesDist = __dirname + '/new_images';
fs.readdir( imagesSrc, function( err, images ) {
if( err ) throw err;
images.forEach(function( image ) {
gm( imagesSrc + '/' + image )
.options({ imageMagick: true })
.rotate( 'none', 90 )
.write( imagesDist + '/' + image, function( err ) {
if( err ) throw err;
console.log( 'Imagem ' + image + ' OK!' );
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment