import { createCanvas, registerFont } from 'canvas'
import fs from 'fs'

const cfg = {
    width: 400,
    height: 400,
    fontPath: 'src/assets/font/obsidian/Obsidian-Roman.otf',
    fontName: 'Obsidian',
    fontWeight: 'bold',
    fontSize: '350pt',
    color: '#fffbe3',
    background: '#111111',
    text: 'g.',
    yOffset: 115,
}

if ( cfg.fontPath ) {
    registerFont(cfg.fontPath, { family: cfg.fontName })
}

const canvas = createCanvas(cfg.width, cfg.height)
const ctx = canvas.getContext('2d')

// set the background
ctx.fillStyle = cfg.background
ctx.fillRect(0, 0, cfg.width, cfg.height)

// set the font
ctx.font = `${cfg.fontWeight} ${cfg.fontSize} ${cfg.fontName}`
ctx.fillStyle = cfg.color
ctx.textAlign = 'center'
ctx.textBaseline = 'middle'

// add the text to the canvas
ctx.fillText(cfg.text, cfg.width / 2, cfg.yOffset)

// write out logo.png
const png = fs.createWriteStream('src/assets/logo/logo.png')
canvas.createPNGStream().pipe(png)

const jpg = fs.createWriteStream('src/assets/logo/logo.jpg')
canvas.createJPEGStream().pipe(jpg)
