-
-
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
compositing image #1630
Comments
Hi, does switching libvips' cache off via |
Hi Lovell, I'm not sure if sharp.cache(false) helps - for sure it does not solve the issue. I can share the code, no problem - how would it be best for you (I can share ? Here the problem snippet sharp.cache(false);
sharp({
create: {
width: 16123,
height: 17973,
channels: 3,
background: { r: 0, g: 0, b: 0}
}
})
.limitInputPixels(false)
.composite(compLayer0)
//.composite(compLayer1)
.toFile(file,(err, info) => {
if (err) {
console.log(err);
} else {
console.log('COMPOSITE written');
}
}); compLayer0 and compLayer1 are both arrays of this shape: {
input: e.image,
// blend: 'source',
top: config.trans_x,
left: config.trans_y,
} If i use both composite layers, only the last layer is present in the output (trying with limited amounts of images, eg 5 each). blend: 'source' did only result in one placed image, hence i commented it. As a side note:
using: sharp.cache(false);
sharp({
create: {
width: 16123,
height: 17973,
channels: 3,
background: { r: 0, g: 0, b: 0}
}
})
.limitInputPixels(false)
.composite(compLayer0)
// .composite(compLayer1)
.raw()
.toBuffer({ resolveWithObject: true })
.then((obj) => {
console.log(obj.info);
}) |
Each layer is ~850MB, hence the rapid memory exhaustion. If there is no overlap then the possible future enhancement detailed in #1580 will help, otherwise you'll need to do this in sections, or a few layers at a time. |
thanks, i naively was expecting the lib to merge down every image one after another. how would i do it in segments? i thought i could do but didnt get that to work. I guess i could get the toBuffer and create a new sharp object, but i'd like to avoid compression and decompression each time. |
To avoid the (de)compression roundtrip try raw pixel input and output. https://sharp.pixelplumbing.com/en/stable/api-constructor/#sharp |
the problem i have with raw is that it results in this error: Assertion failed: (length <= imp::kMaxLength && "too large buffer"), function NewBuffer, file ../node_modules/nan/nan.h, line 823. |
An alternative might be to try an SVG with positioned, inline base64-encoded |
interesting idea, but unfortunately I need the end result as either a jpg or png for further processing. I guess i'll look into moving that part over to python |
You can convert from SVG to PNG using |
sounds interesting, i'll give it a try - though first time using svg. do you know how svg handles if those placed images overlap? |
I'm also having huge memory issues with composite. I saw the arrayjoin() feature from VIPS that would perfectly fit my needs so i'm gonna give it a try although i like "zero dependency" of sharp ^^. Thank you for your work ! Regards, |
I'll give the svg a later try. The python variant works fine. It feels as if composite currently places every image which needs placement into a new image of the target image size and in the end merges the complete stack. In my case the top layer just wins without any blending, hence just placing each image onto the target works fine, and does not blow up the memory usage. Numpy is currently fast enough as well |
I'll close this as I'm not sure what else can be done for now but please do subscribe to #1580 for updates about the future possible feature that will definitely help. |
@lovell how would i go about creating the svg that i can composite tiles to? even with a 1024x1024 composite i'm getting crashes in node (expressjs). i tried:
and
and this keeps crashing. |
hi, i'm trying to create a big image out of several small images (about 250).
composite works fine for few images, but if the number gets bigger the ram usage explodes and it does not finish anymore.
i've tried to split it up into chaining several composite calls, but it appears that this does not work.
any hint how i could combine these images into a large one? most of the images do not overlap, though a few do.
The text was updated successfully, but these errors were encountered: