1

I'm trying to compose a ton of images (2300) into a transparent png using sharp. I'm trying that with the following code:

await sharp({
    create: {
      width: 256,
      height: 256,
      channels: 4,
      background: { r: 0, g: 0, b: 0, alpha: 0 },
    },
  })
    .composite(images)
    .png()
    .toBuffer();

Where images is an array generated like this:

const pinSvg = fs.readFileSync("./icon_web_pin_record_basic.svg");
const pinWidth = 18;
const pinHeight = 25;
const generateImageFromLocationArray = (locations) => {
  const images = [];
  for (let i = 0; i < locations.length; i++) {
    const [x, y] = locations[i];
    images.push({
      input: pinSvg,
      blend: "add",
      left: x - Math.floor(pinWidth / 2),
      top: y - pinHeight,
    });
  }
  return images;
};

With a few images, everything works fine, but with 2300 images, I get the following error:

[1]    12202 bus error  node index.js

I have tried to set sharp.cache(false), but that has not worked. Any idea how to solve it? I suppose I'm getting some overflow, but I do not know how to fix it.

Antonio Gamiz Delgado
  • 1,871
  • 1
  • 12
  • 33

0 Answers0