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

Resize and Composite happen out of order #1790

Closed
f0x52 opened this issue Jul 12, 2019 · 4 comments
Closed

Resize and Composite happen out of order #1790

f0x52 opened this issue Jul 12, 2019 · 4 comments
Labels

Comments

@f0x52
Copy link

f0x52 commented Jul 12, 2019

What is the output of running npx envinfo --binaries --languages --system --utilities?

  System:
    OS: Linux 4.19 Debian GNU/Linux 10 (buster) 10 (buster)
    CPU: (4) x64 Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
    Memory: 720.52 MB / 7.09 GB
    Container: Yes
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 10.16.0 - /usr/bin/node
    Yarn: 1.12.3 - /usr/bin/yarn
    npm: 6.9.0 - /usr/bin/npm
  Utilities:
    CMake: 3.13.4 - /usr/bin/cmake
    Make: 4.2.1 - /usr/bin/make
    GCC: 8.3.0 - /usr/bin/gcc
    Git: 2.20.1 - /usr/bin/git
  Languages:
    Bash: 5.0.3 - /bin/bash
    Go: 1.11.6 - /usr/bin/go
    Elixir: 1.8.2 - /usr/bin/elixir
    Java: 1.8.0_201 - /usr/bin/javac
    Perl: 5.28.1 - /usr/bin/perl
    Python: 2.7.16 - /usr/bin/python
    Ruby: 2.5.5 - /usr/bin/ruby
    Rust: 1.17.0 - /home/f0x/.cargo/bin/rustup

What are the steps to reproduce?
Having a resize operation after a composite, will result in the composite happening on the resized image.

What is the expected behaviour?
The composite should happen first, because it's earlier in the line. After that, the image should get the resize

Are you able to provide a standalone code sample, without other dependencies, that demonstrates this problem?

const sharp = require('sharp');
sharp({create: {height: 100, width: 100, channels: 3, background: 'red'}})
	.composite([{input: {create: {width: 10, height: 10, channels: 3, background: 'green'}}, gravity: "southwest"}])
	.resize({width: 300, height: 300})
	.toFile("out.png")

The green square will still be 10x10 pixels, instead of being resized with the original image.

@f0x52
Copy link
Author

f0x52 commented Jul 12, 2019

This also happens when using extend

@lovell
Copy link
Owner

lovell commented Jul 17, 2019

Hi, you'll need to break this into two pipelines, something like:

const composited = await sharp({create: {height: 100, width: 100, channels: 3, background: 'red'}})
  .composite([{input: {create: {width: 10, height: 10, channels: 3, background: 'green'}}, gravity: "southwest"}])
  .png();
  .toBuffer();

sharp(composited)
  .resize({width: 300, height: 300})
  .toFile("out.png");

@joepie91
Copy link

This seems like either an implementation bug or an API bug to me, rather than a question. When a fluent API is offered, surely it is reasonable to expect that inherently-ordered operations expressed with it are actually processed in the specified order?

I can understand that it might be necessary on a technical level to break it into two pipelines, but isn't that something that the library should be doing internally as-needed? This way it seems like a leaky abstraction to me, where you need to know exactly how something is internally processed to know where it is valid to use a particular operation.

@lovell
Copy link
Owner

lovell commented Jul 17, 2019

@joepie91 Please see #241

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

3 participants