Fonts
To generate images through Satori a font is required, system fonts can't be used. To
avoid issues, the module will use
You can customise the font by using the
For using non-english fonts you should read Non-English Locales guide for a workaround.
Loading A Google Font
Google fonts are recommended as their format will always be supported. To use
Google Fonts simply provide the array of fonts you want to use using
This will download and cache the font when you first run your app.
export default defineNuxtConfig({
ogImage: {
fonts: [
// will load the Noto Sans font from Google fonts
'Noto+Sans:400',
'Noto+Sans:700'
]
}
})
Note: Providing your own fonts will disable the default
Google Font API Mirror
If you're in China or the Google APIs are blocked for you for some reason, you can opt-in to the Google Font Mirror.
export default defineNuxtConfig({
ogImage: {
googleFontMirror: true
}
})
This will use the
Loading A Local Font File
Local font files must be either
For example, if you have a font file at
export default defineNuxtConfig({
ogImage: {
fonts: [
{
name: 'optieinstein',
weight: 800,
// path must point to a public font file
path: '/fonts/OPTIEinstein-Black.otf',
}
],
}
})
Template Custom Fonts
Sometimes you'll be rendering a custom template that you want to use a custom font with, without having to load that font for all templates.
In this case, you can use the
defineOgImage({
fonts: [
{
name: 'optieinstein',
weight: 800,
path: '/fonts/OPTIEinstein-Black.otf',
}
]
})
Using A Custom Font In Your Template
To use your custom fonts, within your template you'll need to set the font-family.
<div style="font-family: 'optieinstein'">
<!-- ... -->
</div>