Hi,
There is a wierd issue when Im trying to resize() after composite(), the source is:
sharp({
create: {
width: 789,
height: 789,
channels: 4,
background: '#bfff00'
}
}).png().composite([{ input: content }]).resize(192).toBuffer((err, data) => {
if (err)
return callback(err);
this.emitFile(target, data);
callback(null, '');
});
And it halted with Image to composite must have same dimensions or smaller.
If I deleted .resize(192), it works fine.
If I deleted .png(), the same error would be occurred again.
You'll need to break this into two pipelines, something like (untested):
sharp({
create: {
width: 789,
height: 789,
channels: 4,
background: '#bfff00'
}
})
.composite([{
input: content
}])
.png()
.toBuffer()
.then(data => sharp(data)
.resize(192)
.toBuffer()
)
.then( ... );
Yup. I finally solved that with two instances :-p
I've encountered the same problem when performing resizing after composition.
Thanks @lovell , this solution indeed works.
But I'm still curious about why a naive combination like
sharp(data).composite(...).resize(...)
doesn't work
I also ran into this issue.
I think, the issue is, that the call order is not used in the different transformations. So it is not important, if you do resize and composite or composite and resize.
Think @johannwagner is correct above, but regardless of the call order, to me it would seem to make more sense if the resize() is applied to the final composite image, not just the input base image, but not sure how others feel about that....?
This is somewhat non-intuitive; a logical expectation would be that compositing images together would also allow them being processed together.
Most helpful comment
You'll need to break this into two pipelines, something like (untested):