canvas
canvas copied to clipboard
How do I register custom fonts and use image links rather than buffer?
I was curious to know how can I register fonts from a local directory without installing them.
See https://github.com/Brooooooklyn/canvas/blob/main/index.d.ts#L280
Also is it possible for me to use the image's as links because as I see, only accepts buffer feed? https://github.com/Brooooooklyn/canvas/blob/main/index.d.ts#L191
Also is it possible for me to use the image's as links because as I see, only accepts buffer feed? https://github.com/Brooooooklyn/canvas/blob/main/index.d.ts#L191
You can use fs
to convert local files to buffer and for links, you can use native https
module or third party modules like node-fetch
fetch("remote_image")
.then(res => res.buffer())
.then(data => /* load this data as image */)
Also #123, I believe there will be a function similar to https://www.npmjs.com/package/canvas#loadimage
@0zul I guess this issue is closable since this lib supports registering custom fonts as well as a utility function to create Image
?
Fonts can be registered with the help of GlobalFonts
as mentioned in https://github.com/Brooooooklyn/canvas#emoji-text
const { GlobalFonts } = require('@napi-rs/canvas')
GlobalFonts.registerFromPath('./somefont.ttf', 'Name Alias')
and images can be loaded via loadImage
utility function (very similar to node-canvas)
const { loadImage } = require('@napi-rs/canvas')
const source = someSource() // source can be file path, url, buffer, etc.
const image = await loadImage(source)