Error : Image to composite must have same dimensions or smaller

See original GitHub issue

Possible bug

Is this a possible bug in a feature of sharp, unrelated to installation?

  • [ x] Running npm install sharp completes without error.
  • [ x] Running node -e "require('sharp')" completes without error.

If you cannot confirm both of these, please open an installation issue instead.

Are you using the latest version of sharp?

  • [x ] I am using the latest version of sharp as reported by npm view sharp dist-tags.latest.

If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.

If you are using another package which depends on a version of sharp that is not the latest, please open an issue against that package instead.

What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?

System: OS: Windows 10 10.0.19044 CPU: (12) x64 Intel® Core™ i7-8750H CPU @ 2.20GHz Memory: 7.02 GB / 15.82 GB Binaries: Node: 14.18.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.11 - ~\AppData\Roaming\npm\yarn.CMD npm: 6.14.15 - C:\Program Files\nodejs\npm.CMD npmPackages: sharp: ^0.30.4 => 0.30.4

Explanation of the issue

I’m trying to composite a .gif animated image w/ animated layers. However, when I add the ‘animated: true’ parameter to the layers to be composed, I get the following error:

Image to composite must have same dimensions or smaller

When I do not set the animated parameter to true the image is static and does not animate. The background and the body are non-animated .gif images, the rest (the composite layers) are supposed to be animated.

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem

let overlay =

    [
        {
            input : body,
            tile: true,
            animated : true,
        },

        {
            input: mouth,
            tile : true,
            animated : true
        },

        {
            input : eyes,
            tile : true,
            animated : true
        }
    ];

    let img = await sharp(background).toBuffer();
    img = await sharp(img).composite(overlay).toBuffer();
    /// img = await sharp(img).resize(1000, 1000).toBuffer();

    await sharp(img).gif()
        .toFile('animate_output/' + id + '.gif',  (err) => {
            if (err === null) {
                console.log("IMAGE n°" + id + "done");
            } else {
                console.log("ERR: ", err)
            }
        });

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lovellcommented, May 8, 2022

The input image (background in this case) needs to have at least the same height as the combined height of all the frames. As it appears to be a solid colour, you could create a new, blank image as the input canvas, something like:

sharp({
  create: {
    width: 1000,
    height: 1000 * frameCount,
    channels: 4,
    background: '#0000ff'
  }
})...
1reaction
EtDucommented, May 6, 2022
traitBuffers.push({
        input: buf,
        tile: isGif ? false : true,
        gravity: 'northwest',
        animated: isGif ? true : false,
        limitInputPixels: 2684026890
      })

let composite = traitBuffers.shift()

finalImage = sharp(composite.input, {
        animated: true,
        limitInputPixels: 2684026890,
      }).composite(traitBuffers).gif({ effort: 1 }).toBuffer()
Read more comments on GitHub >

github_iconTop Results From Across the Web

Image to composite must have same dimensions or smaller ...
The operation composite should allow greater images than the source image. It should use the source image dimensions.
Read more >
Compositing images - sharp - Sharp
The images to composite must be the same size or smaller than the processed image. If both top and left options are provided,...
Read more >
Defining a Composite Image
If the size of the data array needed to construct the composite image is larger in either dimension than the current program array...
Read more >
Processing images with sharp in Node.js - LogRocket Blog
It is important to note that the composite image must have smaller dimensions than the processed image. We can specify the following object ......
Read more >
sharp composite not work as expected, composite auto re ...
i expected composite takes array of object image to place with position. but what i got is just original output. first i extract...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found