I'm working on a project where I need to extract a piece of an image and then mask the extracted image with a polygon shape and then rotate it. I am using an SVG string buffer as the mask.
When I run this line of code with rotate() I get an error:
"Overlay image must have same dimensions or smaller"
sharp(imageData)
.extract({left: left, top: top, width: width, height: height})
.overlayWith(mask, {cutout: true})
.flip(isMirrored)
.rotate(rotation)
.png()
.toFile(filePath);
When I run it without the rotate call, it runs without error. I am not sure if this is an actual bug or if I may be doing something wrong. I am assuming that the overlayWith is happening after the rotation and that may be what is causing the error.
I also want to thank you for creating this library. It is brilliant!
Hello, your guess is correct, the overlay is applied at the end. You'll probably need to split this into two pipelines, something like:
sharp(imageData)
.extract({left: left, top: top, width: width, height: height})
.overlayWith(mask, { cutout: true })
.raw()
.toBuffer({ resolveWithObject: true })
.then(({ data, info }) => sharp(data, { raw: info })
.flip(isMirrored)
.rotate(rotation)
.png()
.toFile(filePath)
);
Ah thanks! I will do it that way.