resize picture with nodeJs imageMagick - node.js

I would like to resize some picture before send to user in nodeJs with express
im = require("imagemagick")
app.get('/image/:dossier/:id/:taille', function (req, res) {
var image = __dirname + '/public/img/bibliotheque/'+req.params.dossier+'/'+req.params.id+'.jpg';
im.resize({
srcPath : image,
width : req.params.taille
},
function(err, stdout, stderr) {
if (err){
log.error(err);
} else {
res.contentType("image/jpeg");
res.end(stdout);
}
});
});
but it's return :
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)
I try to launch my app with and without sudo but no change
I'm on OSX
Please, help me

You need to install the application in addition to the npm module.
brew install imagemagick

Related

error on doing "Truffle init"

I am new to smart contract programming, recently installed truffle using npm on Node(version: 6.10.3)
When I run the command truffle init first time, I received this error:
events.js:160
throw er; // Unhandled 'error' event
^
Error: connect ETIMEDOUT 151.101.8.133:443
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
The next time I run truffle init, I got ths error:
events.js:160
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at exports._errnoException (util.js:1018:11)
at TLSWrap.onread (net.js:568:26)
Any idea on how to resolve this
I was also facing a similar issue when I tried to execute truffle init behind a corporate http proxy and found a workaround.
Modified the cli.bundled.js: replaced https.request with request
Diff:
diff --git a/build/cli.bundled.js b/build/cli.bundled.js
index 01c69e3..aa2605c 100755
--- a/build/cli.bundled.js
+++ b/build/cli.bundled.js
## -202412,12 +202412,8 ## var Init = {
// will fail spectacularly in a way we can't catch, so we have to do it ourselves.
return new Promise(function(accept, reject) {
- var options = {
- method: 'HEAD',
- host: 'raw.githubusercontent.com',
- path: '/trufflesuite/' + expected_full_name + "/master/truffle.js"
- };
- req = https.request(options, function(r) {
+ var request = require('request');
+ request({ method: 'HEAD', uri: 'https://raw.githubusercontent.com/trufflesuite/'+expected_full_name+'/master/truffle.js'}, function (error, r, body) {
if (r.statusCode == 404) {
return reject(new Error("Example '" + name + "' doesn't exist. If you believe this is an error, please contact Truffle support."));
} else if (r.statusCode != 200) {
## -202425,7 +202421,6 ## var Init = {
}
accept();
});
- req.end();
});
}).then(function() {
## -212634,4 +212629,4 ## module.exports = require("solc");
module.exports = require("string_decoder");
/***/ })
-/******/ ]);
\ No newline at end of file
+/******/ ]);
Prerequisite:
Install request via npm (npm install -g request)
Proxy - setup enviroment as described here
Without code it is pretty difficult to say where this goes wrong. But do you have a ethereum rpc node running on the port specified in the truffle configuration.
Truffle configuration
When inspecting your error code I see you try to connect to 151.101.8.133:443 is there an rpc node running on this port?

Node.js ENOENT Reading PDF file

I need to read pdf file and I use pdf-text-extract. It works perfectly on my localhost. But when I tried to run the program on server, I got the following error
spawn called
{ '0': 'pdftotext',
'1':
[ '-layout',
'-enc',
'UTF-8',
'/tmp/the_file_name.pdf',
'-' ],
'2': { encoding: 'UTF-8', layout: 'layout', splitPages: true } }
events.js:72
throw er; // Unhandled 'error' event
Error: spawn ENOENT
at errnoException (child_process.js:1011:11)
at Process.ChildProcess._handle.onexit (child_process.js:802:34)
Here is how I use pdf-text-extract
var extract = require('pdf-text-extract');
.....
.then (function () {
console.log(fs.readdirSync('/tmp'));
var extractAsync = Promise.promisify(extract);
return extractAsync(filePath);
})
.catch (function (err) {
console.log(err);
});
As you can see, I have added catch, but why the error is Unhandled 'error' event.
I have also checked that the file is exist using fs.readdirSync. What cause the error and how can I fix it?
Your server does not have the pdftotext command, which the pdf-text-extract module tries to spawn as a child process. The readme for the module includes a link to how to install the program for various platforms.

Webshot fails on Meteor in DigitalOcean Ubuntu 14.04

I am using this code to generate pdf:
let fileUri = process.env.PWD + '/storage/orders-pdf/' + fileName;
// Commence Webshot
webshot(html_string, fileUri, options, function(error) {
fs.readFile(fileUri, function (err, data) {
if (err) {
return console.log(err);
}
fs.unlinkSync(fileUri);
fut.return(data);
});
});
let pdfData = fut.wait();
But it throws the following error:
{ [Error: ENOENT, open '/opt/holi/storage/orders-pdf/Attributes.pdf']
errno: 34,
code: 'ENOENT',
path: '/opt/holi/storage/orders-pdf/Attributes.pdf' }
Tried to use npm package https://github.com/brenden/node-webshot
Then code works perfectly on localhost, but fails on the server and throws this error:
EDIT:
Even when running webshot without:
fs.readFile(fileUri, function (err, data) {
if (err) {
return console.log(err);
}
fs.unlinkSync(fileUri);
fut.return(data);
});
The file is not created..
EDIT-2:
Webshot throws an error: [Error: PhantomJS exited with return value 2]
EDIT-3:
Actual issue: https://github.com/brenden/node-webshot/issues/123
I had a similar problem, and spent most of the day trying to figure out the issue. I ended up adding:
"phantomPath": "/usr/bin/phantomjs"
to my webshot options object. The phantom path I used is where mup installs phantomjs on your server setup.

Node js + imagemagick + Error: spawn ENOENT

Hi am trying to implement Imagemagick package using node.js
I added my following code.
var im = require('imagemagick');
router.post('/conversation/start', function(req, res) {
var args = ["/public/images/team/rajini.jpg", "-crop", "120x80+30+15", "output.png"];
im.convert(args, function(err) {
if (err) {
throw err;
}
res.end("Image crop complete");
});
});
But i getting the following error in terminal.
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:988:11)
at Process.ChildProcess._handle.onexit (child_process.js:779:34)
npm ERR! weird error 8
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

Forever-monitor throwing ENOENT and not working

so I have:
var forever = require('forever-monitor');
var Monitor = forever.Monitor;
var child = new Monitor('clusters.js', {
max: 10,
silent: false,
killTree: true,
logFile: './logs/forever.log',
outFile: './logs/app.log',
errFile: './logs/error.log'
});
child.on('exit', function (err) {
console.log('Server exitted');
});
child.start();
and it always throw the same error: events.js:72 throw er; // Unhandled 'error' event with:
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)
npm ERR! weird error 8
npm ERR! not ok code 0
Does anyone know what is going on and how to fix it?
Im on Windows 7 with:
"express": "3.3.5",
"forever-monitor": "~1.2.2"
https://github.com/blai/grunt-express/issues/12
Apparently the problem is with forever-monitor 1.2, I downgraded to 1.1 and it just worked.
From what I got there they dont seem to be doing anything about it either...

Resources