You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After trimming an image with .trim() you receive an info object, which includes the trimOffsetLeft and trimOffsetTop properties.
However, a picture can be asymmetric, meaning that .trim() will remove differing amounts of border on each side => trimOffsetLeft !== trimOffsetRight.
The current workaround is to calculate the right and bottom offset by hand, with the use of pre-processing metadata and properties included in the resulting info object,
This is the formula used:
Other Offset = Original Length - New Length - |Opposite Offset|
constimage=sharp(inputFile);constdata=awaitimage.metadata();constbuffer1=awaitimage.trim().toBuffer({resolveWithObject: true});// we get new data after .trim()constinfo=buffer1.info;consttrimOffset={left: Math.abs(info.trimOffsetLeft),right: data.width-info.width-Math.abs(info.trimOffsetLeft),top: Math.abs(info.trimOffsetTop),bottom: data.height-info.height-Math.abs(info.trimOffsetTop),};
Additionally, perhaps the original pre-processing values, such as original width & original height could be included in the resulting info object.
The text was updated successfully, but these errors were encountered:
Feature request
After trimming an image with
.trim()
you receive an info object, which includes thetrimOffsetLeft
andtrimOffsetTop
properties.However, a picture can be asymmetric, meaning that
.trim()
will remove differing amounts of border on each side =>trimOffsetLeft
!==trimOffsetRight
.The current workaround is to calculate the right and bottom offset by hand, with the use of pre-processing metadata and properties included in the resulting info object,
This is the formula used:
Additionally, perhaps the original pre-processing values, such as original width & original height could be included in the resulting info object.
The text was updated successfully, but these errors were encountered: