Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added arm support for RPI #12

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
.idea
package-lock.json


Binary file added capture/bin/arm/scrot
Binary file not shown.
27 changes: 4 additions & 23 deletions capture/darwin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,23 @@ module.exports = function(options, callback) {
var fs = require('fs');
var childProcess = require('child_process');

// due to bug in jpgjs processing OSX jpg images https://github.com/notmasteryet/jpgjs/issues/34
// due to bug in jpgjs processing OSX jpg images https://github.com/notmasteryet/jpgjs/issues/34
// when requesting JPG capture as PNG, so JIMP can read it
var ext = extension(options.output);
if(ext === "jpeg" || ext === "jpg") {
options.intermediate = path.resolve(path.join(__dirname, uniqueId() + ".png")); // create an intermediate file that can be processed, then deleted
capture(options.intermediate, callbackReturn);
}
else
capture(options.output, callbackReturn); // when jpegjs bug fixed, only need this line
/* the previuos error seems already corrected */
capture(options.output, callbackReturn); // when jpegjs bug fixed, only need this line

function callbackReturn(error, success) {
// called from capture
// callback with options, in case options added
callback(error, options);
}

function uniqueId() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}

function extension(file) {
return path.extname(file).toLowerCase().substring(1);
}

function capture(output, callback) {
var cmd = "screencapture";
var args = [
// will create PNG by default
"-t",
path.extname(output).toLowerCase().substring(1),
path.extname(file).toLowerCase().substring(1),
"-x",
output
];
Expand Down
6 changes: 6 additions & 0 deletions capture/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict'
exports = module.exports = {
darwin: require('./darwin'),
linux: require('./linux'),
win32: require('./win32')
}
2 changes: 1 addition & 1 deletion capture/linux.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = function(options, callback) {
var childProcess = require('child_process');
var path = require('path');

var scrot = childProcess.spawn(path.join(__dirname, "bin", "scrot", "scrot"), [options.output]);
var scrot = childProcess.spawn(path.join(__dirname, "bin", process.arch !== "arm" ? "scrot" : "arm", "scrot"), [options.output]);
scrot.on('close', function(code, signal) {
try {
fs.statSync(options.output);
Expand Down
48 changes: 26 additions & 22 deletions module.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,26 @@ module.exports = function() {
return new Screenshot(arguments);
};

var path = require('flavored-path');
var path = require('path');
var jimp = require('jimp');
var fs = require('fs');
var capture = require('./capture')

function Screenshot(args) {
var config = this.parseArgs(args);
var self = this;

try {
require("./capture/" + process.platform + ".js")(config.options, function(error, options) {
// TODO add option for string, rather than file
if(error && typeof config.callback === "function")
config.callback(error, null);
else if(!error) {
if (typeof options.intermediate === "string") {
self.processImage(options.intermediate, options.output, options, function (error, success) {
fs.unlink(options.intermediate, handleCallback); // delete intermediate
});
}
else
self.processImage(options.output, options.output, options, handleCallback);
}
});
}
catch(error) {
if(typeof error == "object" && typeof error.code === "string" && error.code === "MODULE_NOT_FOUND")
handleCallback("unsupported_platform");
if(capture[process.platform]){
capture[process.platform](config.options, function(error, options) {
// TODO add option for string, rather than file
if(error && typeof config.callback === "function")
config.callback(error, null);
else if(!error) {
self.processImage(options.output, options.output, options, handleCallback);
}
});
} else {
handleCallback("unsupported_platform");
}

function handleCallback(error, success) {
Expand Down Expand Up @@ -61,7 +54,18 @@ Screenshot.prototype.processImage = function(input, output, options, callback) {
if(typeof options.quality === "number" && options.quality >= 0 && options.quality <= 100)
image.quality(Math.floor(options.quality)); // only works with JPEGs

image.write(output, callback);
if(options.buffered){
image.getBuffer(jimp.AUTO, function(error, buffer) {
if(error) {
callback(error);
}
fs.unlink(input, function(errorUnlink) {
callback(errorUnlink, buffer);
})
});
} else {
image.write(output, callback);
}
}
catch(error) {
callback(error);
Expand All @@ -83,7 +87,7 @@ Screenshot.prototype.parseArgs = function(args) {
config.callback = args[property];
break;
case "object":
if(args[property] != null)
if(args[property] !== null)
config.options = args[property];
break;
}
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"url": "https://github.com/johnvmt/node-desktop-screenshot"
},
"dependencies": {
"jimp": "0.2.x",
"flavored-path": "0.0.x"
"jimp": "0.2.x"
},
"main": "module.js"
}