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
# Only final operation available in composite chain #2856
Comments
This is the correct approach, which can be mixed with await as follows: .composite([
{
input: await sourceOfImage1(),
...
},
{
input: await sourceOfImage2(),
...
}
] If you're using .composite([
{
input: {
create: {
height: 100, width: 300, channels: 4, background: 'black'
}
},
...
}
] |
Thank you for your confirm! but I encountered a strange problem while rewriting. It looks like a memory leak? Below is an reproduce case. In this case, I loop await to generate a tile array, and composite them to the background layer. const sharp = require("sharp");
const ROW_LENGTH = 180
const createTileBuffer = async function () {
const tile = sharp({
create: { height: 150, width: 150, channels: 4, background: '#fff' }
});
return tile.png().toBuffer();
}
const run = async function () {
const tiles = [];
for (const index in Array.from({ length: ROW_LENGTH })) {
tiles.push(await createTileBuffer())
}
const rowBg = sharp({
create: { height: 150, width: ROW_LENGTH * 150, channels: 4, background: '#fff' }
});
const rowSharp = rowBg.composite(tiles.map((input, index) => ({
input,
blend: 'atop',
top: 0,
left: index * 150
})));
// Error will be thrown here
await rowSharp.toBuffer()
}
run() When I run {
"scripts": {
"case": "node test.js"
}
}
Add run PS D:\project\source> npm run case
> screeps-world-printer@1.0.0 case D:\project\source
> node test.js
npm ERR! code ELIFECYCLE
npm ERR! errno 3221225725
npm ERR! screeps-world-printer@1.0.0 case: `node test.js`
npm ERR! Exit status 3221225725
npm ERR!
npm ERR! Failed at the screeps-world-printer@1.0.0 case script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\huangpuguang\AppData\Roaming\npm-cache\_logs\2021-08-30T12_29_35_503Z-debug.log And yarn output same: PS D:\project\source> yarn run case
yarn run v1.22.10
$ node test.js
error Command failed with exit code 3221225725.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. But when I commented Here is my
|
I reproduced this issue on github actions machine.
|
Exit code 3221225725 looks like a stack overflow so you'll need to break this up into a number of pipelines. I notice you've already seen #2286. |
Yes, it's not hard to solve, I'm just confused about the unexpected behavior of the composite chain. Anyway, thank you for created such a cool project! |
What are you trying to achieve?
Every
composite
operation in the chain can be found in the final result.Have you searched for similar questions?
I found similar problem and solution in the following issue, but the problem still confuses me.
Are you able to provide a minimal, standalone code sample that demonstrates this question?
here is a simple case, I created a
1 * 3
black rectangle, and then calledcomposite
three times to try to fill it with1 * 1
blue tiles.In my expectation, the entire picture will be filled with blue, but the final result shows that only the last
composite
takes effect:What am I thinking
I know that I can use
.composite([ ..., ..., ... ])
to combine multiple layers at the same time, but I need to get each tile through an async function, so I try to solve this through areduce
, and then the problem occurs.With searching issue, I found that I can finish job by executing
toBuffer
after eachcomposite
and then re-instancing withsharp()
. But I'm dealing with a large tilemap, and every buffering/instancing will take a lot of time.So, below is my question:
The text was updated successfully, but these errors were encountered: