Extending sharp::CalculateCrop to work for gravity specified using random x,y coordinates
See original GitHub issueThis can solve a use case where you want to specify a custom x,y centre for the focus region of the image. Can be exposed as .crop({x : xCenter, y : yCenter})
Let me know your thoughts on this
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
python - Calculate area of polygon given (x,y) coordinates
and simple to use: from shapely.geometry import Polygon pgon = Polygon(zip(x, y)) # Assuming the OP's x,y coordinates print(pgon.area) ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Works. But the idea was to abstract out this logic inside of sharp. Let me know if it sounds like a good idea to develop it separately. Closing the issue for now.
If anyone else lands on this issue, this is how you can solve it with
resize
andextract
. Metadata is of the original image for which the focal point is known.height
,width
is the final size requiredobj
The new focus point in the intermediate resize will be at
xCenter / factor
andyCenter / factor
If intermediate height is less than width, set
left
tonewXCenter - (width / 2)
else settop
tonewYCenter - (height / 2)
for extractRemeber to check the
left
ortop
for < 0 and more than the maximum possible for the requiredheight
orwidth
Here’s a complete implementation (in TypeScript) of the method described above by @rn4391:
It can be used as follows: