smartcrop-cli
smartcrop-cli copied to clipboard
Error: Stream yields empty buffer
node: v7.10.0 npm: v5.0.0
❯ smartcrop --width 100 --height 100 avatar.jpg
Error: Stream yields empty buffer
at Socket.<anonymous> (/usr/local/lib/node_modules/smartcrop-cli/node_modules/gm/lib/command.js:57:17)
at emitNone (events.js:91:20)
at Socket.emit (events.js:188:7)
at endReadableNT (_stream_readable.js:975:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
Hello Alex,
First sorry for the slow reply.
I can't reproduce this issue. Can you please provide me the image in question and the version of image magick that you are using (convert --version)?
Cheers, Jonas
I found the issue. Running convert --version gave me an error since my globally set version of Ruby didn't have it. Looks like my last upgrade was what caused the trouble.
Here's my $PATH:
.git/safe/../../bin
/Users/alexbaldwin/.rbenv/shims
/Users/alexbaldwin/.bin
/usr/local/sbin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/opt/X11/bin
/usr/local/MacGPG2/bin
/Users/alexbaldwin/.fzf/bin
Any ideas how I can force /usr/local/bin to take priority over rbenv?
Hello Alex, I'm not sure what rbenv has got to do with smartcrop. But the priority of the paths in $PATH is defined by the order so just change that and you should be good to go.
Cheers, Jonas
Windows 7 x64, Node 20.2.0
$ smartcrop --width 100 --height 100 out.jpg out-t.jpg
Error: Stream yields empty buffer
at Socket.<anonymous> (C:\Node\node_modules\smartcrop-cli\node_modules\gm\lib\command.js:56:21)
at Socket.emit (node:events:523:35)
at endReadableNT (node:internal/streams/readable:1367:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
If this is related to convert, how do I change the call to magick convert?
@sergeevabc what magick version are you running?
@jwagner, the latest one. Point is that Windows has its own convert utility, which has a higher priority, so the command magick or magick convert is used instead.
$ where convert.exe
C:\Windows\System32\convert.exe
C:\Apps\Media\IM\convert.exe
$ where magick.exe
C:\Apps\Media\IM\magick.exe
@sergeevabc
Thanks for the explanation. It's been a long time since I've done any software development on windows.
Could you check to see if changing https://github.com/jwagner/smartcrop-cli/blob/master/smartcrop-cli.js#L53 from
var gm = require('gm').subClass({ imageMagick: true });
to
var gm = require('gm').subClass({ imageMagick: '7+' });
resolves the issue?
If it doesn't we'd need to add an option to pass in the app path via an argument. You could test that like this
var gm = require('gm').subClass({
appPath: String.raw`C:\Apps\Media\IM\magick.exe`
});
var gm = require('gm').subClass({ imageMagick: '7+' });
and
var gm = require('gm').subClass({
appPath: String.raw`C:\Apps\Media\IM\magick.exe`
});
did not bring relief, the error is the same
$ smartcrop --width 100 --height 100 in.png out.png
Error: Stream yields empty buffer
at Socket.<anonymous> (C:\Node\node_modules\smartcrop-cli\node_modules\gm\lib\command.js:56:21)
at Socket.emit (node:events:523:35)
at endReadableNT (node:internal/streams/readable:1367:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Maybe that's because the GM module is outdated. The constraint in the package.json is "gm": "^1.23.1", so that should include the current 1.25.0 but it's the only guess I have right now.
Does the GM package work for you (outside of smartcrop-cli)?
Edit: Just one more random idea, maybe
var gm = require('gm').subClass({
appPath: String.raw`C:\Apps\Media\IM\magick.exe`,
imageMagick: '7+'
});
would work.
Does the GM package work for you (outside of smartcrop-cli)?
I installed the package and tried a basic command, but there was no output at all.
$ npm install gm -g
$ node -e "const gm = require('gm').subClass({appPath: String.raw`C:\im\magick.exe`}); gm('c:\im\in.png').identify();"
At least the following one still works as expected
$ node -e "console.log('Hello, world!')"
Hello, world!
To get some output you need to log something:
.identify(function (err, data) {
console.log(err, data)
});
'c:\im\in.png' likely also won't work, because the \i acts as escape sequence. Using String.raw`content` prevents that.
Some good news, Jonas.
var gm = require('gm').subClass({
appPath: String.raw`C:\im\magick.exe`
});
gm(String.raw`c:\in.png`).identify(function (err, data) {
console.log(err, data)
});
threw an error as follows
Error: Could not execute GraphicsMagick/ImageMagick: C:\im\magick.exegm "identify" "-ping" "-verbose" "c:\in.png" this most likely means the gm/convert binaries can't be found
at ChildProcess.<anonymous> (C:\Node\node_modules\gm\lib\command.js:249:12)
at ChildProcess.emit (node:events:511:28)
at cp.emit (C:\Node\node_modules\gm\node_modules\cross-spawn\lib\enoent.js:36:37)
at ChildProcess._handle.onexit (node:internal/child_process:293:12) {}
However, this one finally worked.
var gm = require('gm').subClass({
imageMagick: '7+'
});
gm(String.raw`c:\in.png`).identify(function (err, data) {
console.log(err, data)
});
Alas, I don't know what to do next, because we've already tried to put imageMagick: '7+' in smartcrop-cli.js