-
-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
deno-canvas supports writing text to a canvas:
import { createCanvas } from 'https://deno.land/x/canvas/mod.ts'
const canvas = createCanvas(500,600)
const ctx = canvas.getContext('2d')
ctx.fillStyle='red'
ctx.fillText(50,50,"Hello World")
await Deno.writeFile("image.png", canvas.toBuffer());this is currently only limited to fonts your system knows about (it might even be more limited than that). Canvas kit has an api for loading custom fonts https://skia.org/docs/user/modules/quickstart/#text-shaping. Itd be great if deno-canvas supported loading custom fonts. I think pulling in the whole paragraph builder api might be substantial, but all I would personally be interested in is mirroring the browser's canvas apis with the addition of being able to load custom fonts. E.g.
import { createCanvas, registerFont } from 'https://deno.land/x/canvas/mod.ts'
const canvas = createCanvas(500,600)
const ctx = canvas.getContext('2d')
await registerFont({
font_family: 'Comic Sans',
// extra fancy would be supporting a url here (e.g. file:///my-fonts/comic-sans.ttf or any web url)
src: './my-fonts/comic-sans.ttf'
})
ctx.font = 'Comic Sans'
ctx.fillStyle='red'
ctx.fillText(50,50,"Hello World")
await Deno.writeFile("image.png", canvas.toBuffer());the registerFont method is very similar to the css interface for loading fonts:
@font-face {
font-family: 'KulminoituvaRegular';
src: url('http://www.miketaylr.com/f/kulminoituva.ttf');
}Metadata
Metadata
Assignees
Labels
No labels