Created
February 7, 2014 05:15
-
-
Save jfensign/8857639 to your computer and use it in GitHub Desktop.
Revisions
-
Joseph Ensign created this gist
Feb 7, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ Thumbnailer = -> Thumbnailer = this fs = require "fs" cp = require "child_process" path = require "path" exec = cp.exec enctype = "binary" ### doc_to_image opts, cb opts = file_path: "/location/of/file/to/convert" #required write_path ### @doc_to_image: (opts, cb) -> filename = opts.file_path.replace path.extname opts.file_path, ".#{opts.convert_to}" is_pdf = path.extname opts.file_path is "pdf" commands = un: "unoconv --stdout #{opts.file_path} | " gs: "gs -q -dNOPAUSE -dBATCH \ -dPDFFitPage -sDEVICE=#{opts.convert_to} \ -r144 -sOutputFile=%stdout \ #{if is_pdf then opts.file_path else '-_'}" writable = fs.createWriteStream path.resolve(opts.write_to, filename), flags: "w" encoding: enctype mode: 0o0777 child_process = exec "#{commands.un}#{commands.gs}", encoding: enctype maxBuffer: 5000 * 1024 writable.on "close", -> cb null, filename, writable child_process.stdout.on "data", (chunk) -> writable.write chunk, enctype child_process.stdout.on "close", -> writable.close() child_process.stderr.on "data", (d) -> console.log d module.exports = new Thumbnailer()