Reputation: 1557
I am trying to use graphicmagick to make a thumbnail of the original image, and I'm trying one of the examples from GM Resize:
var gm = require('gm').subClass({
imageMagick: true
});
var currentDir = __dirname + "\\imgs";
//var gm = require('gm');
console.log(currentDir);
gm(currentDir + "\\Balls.jpg")
.resize(58, 50, '%')
.write(currentDir+"\\newImage.jpg", function (err) {
if (err) return console.dir(arguments)
console.log(this.outname + " created :: " + arguments[3])
});
It will not show the path error after this micro fix. But it gives me another error:
{ '0':
{ [Error: Command failed: Invalid Parameter - -resize
] code: 4, signal: null },
'1': '',
'2': 'Invalid Parameter - -resize\r\n',
'3': 'convert "C:\\Users\\ltang\\Documents\\GitHub\\testMyGM\\imgs\\Balls.jpg" "-resize" "58x50%" "C:\\Users\\ltang\\Documents\\GitHub\\testMyGM\\imgs\\newImage.jpg"' }
Anyone knows why "resize\r\n" appears?
Update
I log my issue here: Invalid Parameter, and I found a way to hack it. But I'm still being curious about why their sample didn't work.
Upvotes: 1
Views: 1487
Reputation: 1557
I hacked this problem, my hack can be done in two steps:
Change the way you import the package:
var gm = require('gm').subClass({
imageMagick: true});
Define your .resize() function in .size() function:
gm(response).size(function(err, size) {
var scalingFactor = Math.min(myWidth /size.width, myWidth / size.height);
var width = scalingFactor * size.width;
var height = scalingFactor * size.height;
var index = key;
this.resize(width, height).toBuffer(
'JPG', function(err,
buffer) {
if (err) {
next(err);
} else {
next(null, buffer, key);
}
}); });
This hack should get rid of the error message, but I also want to know why it cause the error for the original approach.
Upvotes: 1
Reputation: 151
not knowing graphicmagick nor nodejs in depth. my answer most likely wrong.
c:/users/xxx/appdata/roaming/npm/npm_cache or something like that, is were you might find output.
have you ran "npm init" to create your package file? if your package is located some place else on your computer?
unix = / windows uses = \
you might try also ./ or .\ or ../ or ..\
you might trying putting in the full path example:
c:\yadayada\yada\moo\dooo\image.jpg
and see what happens. and then do same thing for your .write
c:\yadayada\yada\moo\dooo\resize.jpg
and see what happens.
Upvotes: 0