Closed hurryhuang1007 closed 1 year ago
The issue with image.insert()
is that libvips has to recurse very deeply when it evaluates the pipeline containing a large amount of images, causing an OOM error or a stack overflow.
If your images are a regular grid, you might consider using vips.Image.arrayjoin()
instead, which would be faster and use much less memory. For example:
const urls = [...];
const images = await Promise.all(
urls.map(async url =>
vips.Image.newFromBuffer(await fetch(url).then(res => res.arrayBuffer()), '', {
access: vips.Access.sequential // 'sequential'
})
)
);
const im = vips.Image.arrayjoin(images, {
across: Math.floor(Math.sqrt(urls.length)), // number of images per row
shim: 10, // space between images, in pixels
background: [0, 0, 0] // background colour
});
const buffer = im.writeToBuffer('.jpg');
I hope this information helped. Please feel free to re-open if questions remain.
Hello, I want to use this library to complete the following tasks: combine multiple small images into one large image in the browser and download it to the user's local. So I write a demo, here are some main code snippets:
Does this mean that large files need to be streamed out? Instead of the overall output as it is now.