-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
How to generate image from stream of raw input? #1579
Comments
Hello, this approach should be supported but sadly, as you point out, it looks like it isn't currently working. There are no unit tests for stream-based input of raw pixel data so this could be a regression, oops. Luckily a small rejig of the logic relating to raw input in _createInputDescriptor should fix this. Happy to accept/help with a PR if you're able. |
Thanks for the quick reply, I’ll start working on it today |
@lovell Hey, I've got sharp building locally, tests pass and all that, ready to take a stab at this But I'm a stream noob and I'm not sure how this change should go in
|
Fantastic, thanks for looking into this. When Stream-based input is expected, There's probably scope for simplification (and definitely a need for testing) but something like the following might work: } else if (!is.defined(input) && is.object(containerOptions) && containerOptions.allowStream) {
// Stream
inputDescriptor.buffer = [];
+ } else if (is.object(input) && is.object(input.raw) && is.object(containerOptions) && containerOptions.allowStream) {
+ // Raw Stream
+ inputDescriptor.buffer = [];
} else {
throw new Error('Unsupported input ' + typeof input); |
For anyone having trouble loading a raw stream, you can can do it by using Example: const pipeline = sharp(null, { raw }).jpeg();
inStream.pipe(pipeline).pipe(outStream); |
Commit 83cdb55 adds a test for this, plus fixes the problem. This will be in v0.22.0 - thanks for reporting! |
v0.22.0 now available. |
I am trying to create an image (ideally to be output as a png) from raw pixel data, but I'm struggling to understand the desired format
I have tried setting
_read
onrs
to pushUint8Array
s,Buffer
s, and other types representing RGB data, but I inevitably get theError: Unexpected data on Writable Stream
errorI'm stumped, any help would be greatly appreciated
The text was updated successfully, but these errors were encountered: