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

At first I didn't understand command chaining, but then I understood separate pipeline instances are needed #2060

Closed
jasonkhanlar opened this issue Jan 30, 2020 · 2 comments
Labels

Comments

@jasonkhanlar
Copy link

jasonkhanlar commented Jan 30, 2020

What are you trying to achieve?
I am trying to understand command chaining, for example resizing sample 500px image down to 4px width, then up to 1000px width so that it appears extremely pixelated

Have you searched for similar questions?
A little bit, but I didn't understand the discussions.

Are you able to provide a standalone code sample that demonstrates this question?

let image_input = await sharp('./image.png'); // assume starting with 500px width
await image_input.resize({ width: 4 }).resize({ width: 1000 }).toFile('./output.png');
console.log('finished');

If I understand correctly, what this does is, resizes 500px to 4px, then proceeds in resizing 500px to 1000px rather than 4px to 1000px

Are you able to provide a sample image that helps explain the question?
Any image will work

@jasonkhanlar
Copy link
Author

jasonkhanlar commented Jan 30, 2020

This also doesn't work as expected.

let image_input = await sharp('./image.png');
let step1 = await image_input.resize({ width: 4 });
let step2 = await step1.resize({ width: 1000 });
let step3 = await step2.toFile('./output.png');

This seems to work, however:

let image_input = await sharp('./image.png');
let step1 = sharp(await image_input.resize({ width: 4 }).toBuffer());
let step2 = sharp(await step1.resize({ width: 1000 }).toBuffer());
let step3 = await step2.toFile('./out.png');

Rather than searching by keywords (command chain, command chaining), I skimmed closed issues and found these:
#2021 -> #1922 -> #241

Then searching for operations and pipelines, I found these:
#230 (I don't see min() anywhere, maybe it's removed/deprecated?)
#235 (didn't help)
#1274 (two pipelines are required)

With that last comment (last link), I tried this code which also works too:

let image_input = await sharp('./image.png');
let step1 = sharp(await image_input.resize({ width: 4 }).toBuffer().then(data => { return data; }));
let step2 = sharp(await step1.resize({ width: 1000 }).toBuffer().then(data => { return data; }));
let step3 = await step2.toFile('./output.png');

@jasonkhanlar
Copy link
Author

☝️ I understand now.

@jasonkhanlar jasonkhanlar changed the title I don't understand command chaining At first I didn't understand command chaining, but then I understood separate pipeline instances are needed Jan 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant