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

Error: Stream yields empty buffer #13

Open
alexbaldwin opened this issue Jun 3, 2017 · 12 comments
Open

Error: Stream yields empty buffer #13

alexbaldwin opened this issue Jun 3, 2017 · 12 comments

Comments

@alexbaldwin
Copy link

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)
@jwagner
Copy link
Owner

jwagner commented Jul 30, 2017

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

@alexbaldwin
Copy link
Author

alexbaldwin commented Aug 2, 2017

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?

@jwagner
Copy link
Owner

jwagner commented Aug 4, 2017

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 jwagner closed this as completed Jan 22, 2018
@sergeevabc
Copy link

sergeevabc commented Feb 8, 2024

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?

@jwagner
Copy link
Owner

jwagner commented Feb 8, 2024

@sergeevabc what magick version are you running?

@sergeevabc
Copy link

sergeevabc commented Feb 8, 2024

@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

@jwagner
Copy link
Owner

jwagner commented Feb 9, 2024

@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 jwagner reopened this Feb 9, 2024
@sergeevabc
Copy link

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)

@jwagner
Copy link
Owner

jwagner commented Feb 11, 2024

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.

@sergeevabc
Copy link

sergeevabc commented Feb 11, 2024

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!

@jwagner
Copy link
Owner

jwagner commented Feb 11, 2024

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.

@sergeevabc
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants