MCPcopy Create free account
hub / github.com/pollinations/pollinations / compose

Function compose

tools/icons/src/render.js:24–50  ·  view source on GitHub ↗

* Core: a tinted logo sized to `fraction` of the shorter side, centered on a * canvas. `bg` is a hex color (opaque background) or null (transparent).

(
    svg,
    { width, height = width, bg = null, logoColor, fraction },
)

Source from the content-addressed store, hash-verified

22 * canvas. `bg` is a hex color (opaque background) or null (transparent).
23 */
24async function compose(
25 svg,
26 { width, height = width, bg = null, logoColor, fraction },
27) {
28 const logoSize = Math.round(Math.min(width, height) * fraction);
29 const logo = await sharp(Buffer.from(tintLogo(svg, logoColor)))
30 .resize(logoSize, logoSize, { fit: "contain", background: TRANSPARENT })
31 .png()
32 .toBuffer();
33 return sharp({
34 create: {
35 width,
36 height,
37 channels: 4,
38 background: bg ? { ...hexToRgb(bg), alpha: 1 } : TRANSPARENT,
39 },
40 })
41 .composite([
42 {
43 input: logo,
44 top: Math.round((height - logoSize) / 2),
45 left: Math.round((width - logoSize) / 2),
46 },
47 ])
48 .png()
49 .toBuffer();
50}
51
52/** Favicon: logo fills the square, transparent background. */
53export function renderFavicon(svg, size, color) {

Callers 3

renderFaviconFunction · 0.85
renderPaddedIconFunction · 0.85
renderSolidIconFunction · 0.85

Calls 2

tintLogoFunction · 0.85
hexToRgbFunction · 0.70

Tested by

no test coverage detected