Utility Functions
Logo Soup exports several utility functions that can be useful for advanced use cases or custom integrations.cropToDataUrl
Crops an image to its content bounding box and returns a data URL.The image element to crop
The bounding box defining the content area to extract
data:image/png;base64,...) containing the cropped image.
Usage
This function uses a canvas to crop the image and returns a data URL. For production use, consider using blob URLs for better memory management.
calculateNormalizedDimensions
Calculates normalized dimensions for a logo based on its measurements and normalization parameters.The measurement result from analyzing the logo
Target size in pixels (typically the height or width reference)
Controls aspect ratio normalization (0 = uniform widths, 1 = uniform heights, 0.5 = balanced)
Controls density compensation strength (0 = no effect, 1 = full effect)
width and height properties representing the normalized dimensions.
Algorithm
This function implements Dan Paquette’s aspect ratio normalization technique:- Density compensation — Scales based on visual weight (pixel density)
- Irradiation compensation — Adjusts for the Helmholtz illusion on dark backgrounds
Usage
createNormalizedLogo
Creates a completeNormalizedLogo object from a logo source and its measurements.
The logo source object with
src and optional altThe measurement result from analyzing the logo
Target size in pixels
Aspect ratio normalization factor (0-1)
Density compensation factor (0-1)
NormalizedLogo object with all computed properties.
Usage
Default Constants
Logo Soup exports constants for all default configuration values. These can be useful for building custom UI controls or understanding the default behavior.Exported Constants
Default alignment mode:
"visual-center-y"Default target size:
48 pixelsDefault contrast threshold:
10 (0-255 scale)Default crop behavior:
falseDefault density compensation:
trueDefault density factor:
0.5 (50% strength)Default gap between logos:
28 pixels (React component only)Default scale factor:
0.5 (balanced aspect ratio normalization)Usage
Related Documentation
- createLogoSoup — Core engine API
- getVisualCenterTransform — Alignment helper
- Types — Complete type definitions
- Options — Configuration reference