info-display/generate-image.ts
2023-05-26 14:04:46 +02:00

35 lines
790 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { createCanvas } from "https://deno.land/x/canvas/mod.ts"
const WeatherInfo = [
' \\ / Sunny',
' .-. 17 °C',
'― ( ) ― ↘ 20 km/h',
' `- 10 km',
' / \\ 0.0 mm',
]
async function genImage(width: number, height: number) {
const canvas = createCanvas(width, height)
const ctx = canvas.getContext('2d')
const fontSize = 16
const lineHeight = fontSize * 1.35
ctx.fillStyle = 'white'
ctx.fillRect(0, 0, width, height)
ctx.fillStyle = 'black'
ctx.font = `${fontSize}px mono`
WeatherInfo.forEach((line, i) => {
ctx.fillText(line, 5, fontSize + lineHeight * i)
})
return Deno.writeFile('generated-image.png', canvas.toBuffer())
}
if (import.meta.main) {
await genImage(800, 480)
}
export default genImage