From ab6fe61136329bf1ae447beb20c6ec0abee08877 Mon Sep 17 00:00:00 2001 From: Kenneth Ormandy Date: Sun, 4 Oct 2015 21:56:07 -0700 Subject: [PATCH] Adds initial image compression test --- lib/img.js | 34 ++++++++++++++++++++++++++++++++++ package.json | 2 ++ 2 files changed, 36 insertions(+) create mode 100644 lib/img.js diff --git a/lib/img.js b/lib/img.js new file mode 100644 index 0000000..756dadb --- /dev/null +++ b/lib/img.js @@ -0,0 +1,34 @@ +var fs = require('fs') +var path = require('path') +var dir = require('node-dir') +var imagemagick = require('imagemagick-native') + +dir.readFilesStream(path.resolve(__dirname, '../src/media/2015/04') , + function (err, stream, next) { + if (err) throw err + var content = '' + stream.on('data', function (buffer) { + content += buffer.toString() + imagemagick.streams.convert({ + srcData: content, + quality: 50, + width: 2500, + resizeStyle: 'aspectfit' // Closest to the max size without altering the ratio + }) + }) + stream.on('end', function () { + next() + }) + }, + function (err, files) { + console.log(files) + if (err) throw err + console.log('Done') + }) + +// +// dir.files(path.resolve(__dirname, '../src/media/2015'), function(err, files) { +// if (err) throw err +// console.log(files) +// +// }) diff --git a/package.json b/package.json index 4e5f939..e66cfab 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "handlebars": "3.0.3", "harp-minify": "0.3.2", "helper-moment": "0.1.0", + "imagemagick-native": "1.8.0", "kss": "2.1.0", "losttype-contributors": "0.4.1", "metalsmith": "1.7.0", @@ -47,6 +48,7 @@ "metalsmith-tags": "0.10.1", "metalsmith-templates": "0.7.0", "metalsmith-typogr": "0.1.0", + "node-dir": "0.1.10", "node-sass": "3.2.0", "nodemon": "1.3.7", "normalize-opentype.css": "0.2.4",