* 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 },
)
| 22 | * canvas. `bg` is a hex color (opaque background) or null (transparent). |
| 23 | */ |
| 24 | async 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. */ |
| 53 | export function renderFavicon(svg, size, color) { |
no test coverage detected