translate() transform to shift a logo from its geometric center to its visual weight center. This compensates for asymmetric logos where the perceived center doesn’t match the bounding box center.
Signature
Parameters
A normalized logo object returned by the engine, hook, or composable. Must have
visualCenter, normalizedWidth, normalizedHeight, and optionally contentBox and originalWidth/originalHeight for scale computation.The alignment mode to use. Determines which axes are compensated.
| Mode | Description |
|---|---|
"bounds" | No transform. Returns undefined. |
"visual-center" | Compensate on both X and Y axes. |
"visual-center-x" | Compensate horizontally only. |
"visual-center-y" | Compensate vertically only (default). |
Returns
string | undefined
- A CSS
translate()string like"translate(0px, -2.3px)"when a meaningful offset exists (greater than 0.5px on either axis). undefinedwhen no adjustment is needed — either becausealignByis"bounds", the logo has novisualCenterdata, or the offset is negligibly small.
Usage
With the React component
The<LogoSoup> component applies this automatically via the alignBy prop. You don’t need to call this function directly when using the component.
With the React hook
When building custom layouts withuseLogoSoup, apply the transform manually:
With other frameworks
How it works
The function computes the offset between a logo’s geometric center and its visual weight center, scaled to the normalized dimensions:- The
visualCenteron eachNormalizedLogocontainsoffsetXandoffsetY— the displacement from the geometric center of the content box, in source image pixels. - These offsets are scaled by the ratio of normalized dimensions to content box dimensions (or original dimensions if no content box exists).
- If the resulting pixel offset exceeds 0.5px on either axis, a
translate()string is returned. Below that threshold, the function returnsundefinedto avoid sub-pixel jitter. - Values are rounded to one decimal place for clean CSS output.
Example offset
Consider a logo where the icon is positioned above the wordmark. The geometric center of the bounding box is between the icon and text, but the visual weight is biased toward the denser wordmark below. ThevisualCenter.offsetY would be positive (shifted down), and getVisualCenterTransform would return a negative Y translate to shift the logo up, centering it on its visual weight.
Why "visual-center-y" is the default
For horizontal logo rows (the most common layout), vertical misalignment is the most noticeable problem. Logos appear to “bounce” up and down relative to each other. Horizontal misalignment is less perceptible because logos already have spacing between them.
Using "visual-center-y" corrects the vertical bounce without introducing unexpected horizontal shifts, which makes it the safest default for most use cases.
Use "visual-center" (both axes) when logos are displayed in a grid or when horizontal balance matters equally.