satori icon indicating copy to clipboard operation
satori copied to clipboard

[Vercel OG] Missing kerning when using custom font

Open mwskwong opened this issue 2 years ago • 1 comments

Bug report

Description / Observed Behavior

If the image generated by @vercel/og contains texts, those texts will not have the kerning correctly applied when using a custom font. image

Expected Behavior

Kerning is applied. image

Reproduction

Unable to demonstrate with https://og-playground.vercel.app, so I created a Next.js repo instead:

HTML: https://vercel-og-kerning.vercel.app/ OG: https://vercel-og-kerning.vercel.app/api/og Repo: https://github.com/mwskwong/vercel-og-kerning

mwskwong avatar Mar 01 '23 02:03 mwskwong

I am experiencing a similar issue where the line-height is different, but it seems to happen more on some fonts than on others. I'm not sure if this is related but it sounds like it could since it is related to the spacing of letters. I notice greater issues with irregular fonts.

While creating the comparison images I also noticed that ligatures don't seem to be rendered correctly (see last example "Henny Penny" which uses ligatures on some repeating letters "ee" "ff" "oo"...)

HTML uses Next/font (google-fonts)

export const montserrat = createMontserrat({
  weight: ["900"],
  subsets: ["latin"],
});

Satori uses TTF downloaded from google-fonts

const montserrat = await fetch(
  new URL("../../../ions/assets/Montserrat/Montserrat-Black.ttf", import.meta.url)
).then(response => response.arrayBuffer());

I explicitly set several values trying to ensure consistent rendering:

const style = {
  fontWeight: "400",
  fontSize: "20px,
  fontFamily: "Montserrat",
  fontStyle: "normal",
  lineHeight: "1.5",
  letterSpacing: "0",
}

There are cases where the line-height is a higher and some where it's lower

HTML Satori
HTML Satori
HTML Satori

pixelass avatar Nov 18 '23 04:11 pixelass