Skip to content
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

Rotate after composite throws "Image to composite must have same dimensions or smaller" #3333

Closed
3 tasks done
DanielStout5 opened this issue Aug 10, 2022 · 3 comments
Closed
3 tasks done
Labels

Comments

@DanielStout5
Copy link

DanielStout5 commented Aug 10, 2022

Possible bug

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

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

Are you using the latest version of sharp?

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

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

  System:
    OS: Windows 10 10.0.19044
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11700F @ 2.50GHz
    Memory: 6.19 GB / 31.73 GB
  Binaries:
    Node: 14.18.1 - C:\Program Files\nodejs\node.EXE
    npm: 6.14.15 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    sharp: 0.30.7 => 0.30.7

What are the steps to reproduce?

Composite an image and then try to rotate the combined result:

  await sharp({
    create: {
      width: 1500,
      height: 1125,
      channels: 3,
      background: "#000",
    },
  })
    .composite([
      {
        input: img,
      },
    ])
    .rotate(90)

What is the expected behaviour?

It should rotate the combined image by 90 degrees, but instead throws Error: Image to composite must have same dimensions or smaller, even though img and the created image are the exact same size.

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

https://github.com/DanielStout5/SharpCompositeRotateBug

Please provide sample image(s) that help explain this problem

Not image specific, but an image is included in the git repo above.

@DanielStout5 DanielStout5 changed the title Rotate after composite does not work Rotate after composite throws "Image to composite must have same dimensions or smaller" Aug 10, 2022
@lovell
Copy link
Owner

lovell commented Aug 21, 2022

Hi, you'll need to break this into two pipelines.

  const composited = await sharp({
    create: {
      width: 1500,
      height: 1125,
      channels: 3,
      background: "#000",
    },
  })
    .composite([
      {
        input: img,
      },
    ])
    .toBuffer();

  await sharp(composited)
    .rotate(90)
    .toFile("out.jpg");

Commit e1bc867 improves the documentation around this.

@lovell lovell added question and removed triage labels Aug 21, 2022
@DanielStout5
Copy link
Author

Ah, okay, thanks for the reply - that's what I had implemented as a workaround but I assume rendering the image out to a buffer just to read it back in is somewhat inefficient.

Is there any chance of another approach being added to Sharp in the future, maybe some way to specify at what point the rotation occurs?

@lovell
Copy link
Owner

lovell commented Aug 22, 2022

Please see the discussion at #241

@lovell lovell closed this as completed Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants