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

Is it possible to access trim offsets for all sides and not just top and left? #3696

Closed
gugiserman opened this issue Jun 12, 2023 · 2 comments
Labels

Comments

@gugiserman
Copy link

gugiserman commented Jun 12, 2023

Question about an existing feature

What are you trying to achieve?

For my specific use case I need to have access to the size that was trimmed from all sides and not just top and left (trimOffsetTop, trimOffsetLeft) returned by the trim method.

The main reason is that I need to save the original position that the actual content had within the transparent background in its original canvas, so that I'm able to "recreate" the image if needed for example, by repositioning the content in a different canvas later.

In my cases there is no guarantee the top/bottom transparent space are equal, and the same applies to left/right as well.

Is it possible to achieve this with sharp right now? I could not find any related issues or discussions and I'm yet to read through the source code.

Something tells me I should be able to achieve this without sharp, before trimming, but I didn't want to come up with a solution that acts different than the trim and end up with inconsistent saved data vs output.

Thanks!

@lovell
Copy link
Owner

lovell commented Jun 12, 2023

You can calculate this using the input and output dimensions.

right offset = input width - output width - left offset
bottom offset = input height - output height - top offset

@gugiserman
Copy link
Author

You can calculate this using the input and output dimensions.

right offset = input width - output width - left offset
bottom offset = input height - output height - top offset

I'm dumb!
Thanks!

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

2 participants