-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Using resize after composite causes merging of composited images? #1908
Comments
Hi, you'll need to break this into two pipelines, the first to composite and the second to resize. const composited = await sharp({ ... }).composite({ ... }).png().toBuffer();
const resized = await sharp(composited).resize({ ... }).toBuffer(); or you could use Streams: const compositor = sharp({ ... }).composite({ ... }).png();
const resizer = sharp().resize({ ... });
compositor.pipe(resizer).pipe( ... ); You should be able to improve the performance of the composite operation by directly creating images, something like (untested): .composite([
{
- input: topLeft,
+ input: create: {
+ width: tileSize,
+ height: tileSize,
+ channels: 4,
+ background: {r: 255, g: 255, b: 0, alpha: 0.5}
+ },
top: 0,
left: 0
}, Please see #1580 for a future possible enhancement that you might like to subscribe to. |
Thanks @lovell - what is the reason this doesn't work as I expected? Is it because the order of operations in a single pipeline is not preserved, and resize happends before composite? If so, maybe it would be good to highlight that fact in the docs for newcomers - unless I've missed it. Indeed I have used two pipelines as a solution, but was hoping maybe I can further reduce it to one if I figure out what doesn't work. |
You may be interested in the discussion at #241. |
I hope this information helped. Please feel free to re-open with more details if further help is required. |
What is the output of running
npx envinfo --binaries --languages --system --utilities
?What are the steps to reproduce?
Stitch four 256x256 images into one 512x512 image, then resize the full result to 256x256.
What is the expected behaviour?
The result should be a single 256x256 image where each quarter of the image is one of the four composited 256x256 images. Not sure if I am using resize in the wrong way, however.
Are you able to provide a standalone code sample, without other dependencies, that demonstrates this problem?
Run this code to see the problem. Comment out the resize line to see the code correctly producing a 512x512 image.
Are you able to provide a sample image that helps explain the problem?
actual result:
result with resize() line commented out:
desired result:
The text was updated successfully, but these errors were encountered: