INNER CODE UNIT · TypeScript

rasterize

PaulWoitaschek/Voice · artwork/src/render/render-icon.ts:30

async function rasterize(svg: string, size: number, zoom: number): Promise<Buffer> {
  if (zoom === 1) {
    return sharp(Buffer.from(svg), { density: 384 }).resize(size, size).png(PNG_OPTIONS).toBuffer()
  }
  // Wrap the source SVG and scale its contents around the center so the inner
  // padding of the adaptive icon disappears — mimics the Play Store circle mask.
  const wrapped = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 108 108">
    <g transform="translate(54 54) scale(${zoom}) translate(-54 -54)">
      ${svg.replace(/<\?xml[^>]*\?>/, '').replace(/<svg[^>]*>/, '').replace(/<\/svg>/, '')}
    </g>
  </svg>`
  return sharp(Buffer.from(wrapped), { density: 384 }).resize(size, size).png(PNG_OPTIONS).toBuffer()
}

async function main() {
  const svg = readFileSync(LOGO_SVG, 'utf8')
  for (const o of OUTPUTS) {
    mkdirSync(dirname(o.path), { recursive: true })

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…