-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Ensure combination of resize and rotate operations is ordered (to match extract and rotate) #3319
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
Comments
Happens for I currently have to do this intermediate step in between resize and rotate to "fix" it by I guess resetting whatever is being mangled internally: image = sharp(await image.png().toBuffer()); |
As you've seen, you'll currently need to break this operation into two pipelines - see #1922, #2086 and related issues. This has come up a few times, and I've been meaning to modify sharp to ensure that the combination of resize+rotate is also "ordered" to match the behaviour of extract+rotate. https://sharp.pixelplumbing.com/api-operation#rotate
Let's use this issue to track that enhancement. |
I'm running into more and more chaining issues where sharp produces unexpected results. For example: image.extract(...).rotate(90).extract(...); The result is a completely different region than expected. I guess the second extract overwrites the first one? So what I currently have to do is, similar to the above workaround, I made this flush function: const flush = async () => {
const {data, info} = await image.raw().toBuffer({resolveWithObject: true});
image = sharp(data, {raw: info});
}; And I call it in between every operation just to be sure sharp chaining issues don't break something. If sharp doesn't really support chaining operations, it shouldn't encourage it via it's API design 😞. Or have some big warnings everywhere that only one operation type per chain is allowed, and only certain orders are supported, and all other quirks and limitations I'm currently not aware of. |
Please see the discussion at #241 |
Emit warnings when previous ops might be ignored Flip and flop now occur before rotate, if any
Commit 212a6e7 improves the situation slightly, adding examples and test cases, as well as emitting warnings when previous calls in the same pipeline will be ignored. This will be in v0.31.0. |
v0.31.0 is now available with these improvements. Let's continue the other parts of this discussion at #241 |
Possible bug
npm install sharp
completes without error.node -e "require('sharp')"
completes without error.sharp
as reported bynpm view sharp dist-tags.latest
.What are the steps to reproduce?
Resize an image into specific dimensions with fill fit mode, then try to rotate it 90 degrees.
What is the expected behavior?
Result image should be rotated, and have
{oldHeight}x{oldWidth}
dimensions, instead, it IS rotated, but somehow retained{oldWidth}x{oldHeight}
dimensions.Code sample
Sample image
painting.jpg
The text was updated successfully, but these errors were encountered: