smartcrop-cli icon indicating copy to clipboard operation
smartcrop-cli copied to clipboard

Error: Stream yields empty buffer

Open alexbaldwin opened this issue 8 years ago • 12 comments
trafficstars

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)

alexbaldwin avatar Jun 03 '17 17:06 alexbaldwin

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

jwagner avatar Jul 30 '17 17:07 jwagner

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?

alexbaldwin avatar Aug 02 '17 18:08 alexbaldwin

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

jwagner avatar Aug 04 '17 23:08 jwagner

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 avatar Feb 08 '24 01:02 sergeevabc

@sergeevabc what magick version are you running?

jwagner avatar Feb 08 '24 23:02 jwagner

@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 avatar Feb 08 '24 23:02 sergeevabc

@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`
});

jwagner avatar Feb 09 '24 11:02 jwagner

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)

sergeevabc avatar Feb 11 '24 13:02 sergeevabc

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.

jwagner avatar Feb 11 '24 13:02 jwagner

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!

sergeevabc avatar Feb 11 '24 14:02 sergeevabc

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.

jwagner avatar Feb 11 '24 19:02 jwagner

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

sergeevabc avatar Feb 12 '24 01:02 sergeevabc