summaryrefslogtreecommitdiffstats
path: root/lib/utils
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-02-12 21:59:49 +0100
committerSamy Pesse <samypesse@gmail.com>2016-02-12 21:59:49 +0100
commit39b6562d1445e9a6c43a377d2a978eefa6458755 (patch)
tree77d530bca613c44e8c8fee8e6944d538d44f3ca7 /lib/utils
parent0d966fe19738089607de3927694ac5f2bd41f03f (diff)
downloadgitbook-39b6562d1445e9a6c43a377d2a978eefa6458755.zip
gitbook-39b6562d1445e9a6c43a377d2a978eefa6458755.tar.gz
gitbook-39b6562d1445e9a6c43a377d2a978eefa6458755.tar.bz2
Add pipeline to outline svg as png
Diffstat (limited to 'lib/utils')
-rw-r--r--lib/utils/fs.js9
-rw-r--r--lib/utils/images.js16
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/utils/fs.js b/lib/utils/fs.js
index 2fa6ff9..7745448 100644
--- a/lib/utils/fs.js
+++ b/lib/utils/fs.js
@@ -1,6 +1,7 @@
var fs = require('graceful-fs');
var mkdirp = require('mkdirp');
var destroy = require('destroy');
+var tmp = require('tmp');
var Promise = require('./promise');
@@ -52,6 +53,11 @@ function fileExists(filename) {
return d.promise;
}
+// Generate temporary file
+function genTmpFile(opts) {
+ return Promise.nfcall(tmp.file, opts)
+ .get(0);
+}
module.exports = {
exists: fileExists,
@@ -62,5 +68,6 @@ module.exports = {
statSync: fs.statSync,
readdir: Promise.nfbind(fs.readdir),
writeStream: writeStream,
- copy: copyFile
+ copy: copyFile,
+ tmpFile: genTmpFile
};
diff --git a/lib/utils/images.js b/lib/utils/images.js
index 3ba0f1f..45bc0b0 100644
--- a/lib/utils/images.js
+++ b/lib/utils/images.js
@@ -2,6 +2,7 @@ var fs = require('fs');
var Promise = require('./promise');
var command = require('./command');
+var fs = require('./fs');
var error = require('./error');
// Convert a svg file to a pmg
@@ -21,7 +22,22 @@ function convertSVGToPNG(source, dest, options) {
});
}
+// Convert a svg buffer to a png file
+function convertSVGBufferToPNG(buf, dest) {
+ // Create a temporary SVG file to convert
+ return fs.tmpFile({
+ postfix: '.svg'
+ })
+ .then(function(tmpSvg) {
+ return fs.writeFile(tmpSvg, buf)
+ .then(function() {
+ return convertSVGToPNG(tmpSvg, dest);
+ });
+ });
+}
+
module.exports = {
convertSVGToPNG: convertSVGToPNG,
+ convertSVGBufferToPNG: convertSVGBufferToPNG,
INVALID: ['.svg']
}; \ No newline at end of file