Skip to content

Instantly share code, notes, and snippets.

@ayashiiiyo
Last active April 22, 2026 11:55
Show Gist options
  • Select an option

  • Save ayashiiiyo/5998fe0d2ab2f799460d89a0a6e671fb to your computer and use it in GitHub Desktop.

Select an option

Save ayashiiiyo/5998fe0d2ab2f799460d89a0a6e671fb to your computer and use it in GitHub Desktop.
import { Canvas, loadImage, FontLibrary } from 'skia-canvas'
import fs from 'fs'
import path from 'path'
const base = '../ba-logo'
const fontDir = path.join(base, 'fonts')
const assetDir = path.join(base, 'assets')
if (!fs.existsSync(base)) fs.mkdirSync(base)
if (!fs.existsSync(fontDir)) fs.mkdirSync(fontDir)
if (!fs.existsSync(assetDir)) fs.mkdirSync(assetDir)
async function download(url, filepath) {
const res = await fetch(url)
const buffer = Buffer.from(await res.arrayBuffer())
fs.writeFileSync(filepath, buffer)
}
const font1 = path.join(fontDir, 'rog.otf')
const font2 = path.join(fontDir, 'glow.otf')
const haloPath = path.join(assetDir, 'halo.png')
const crossPath = path.join(assetDir, 'cross.png')
if (!fs.existsSync(font1)) await download('https://raw.githubusercontent.com/uploader762/dat2/main/uploads/12678c-1776550380548.otf', font1)
if (!fs.existsSync(font2)) await download('https://raw.githubusercontent.com/uploader762/dat4/main/uploads/403297-1776550542453.otf', font2)
if (!fs.existsSync(haloPath)) await download('https://raw.githubusercontent.com/uploader762/dat4/main/uploads/6e7793-1776550173537.png', haloPath)
if (!fs.existsSync(crossPath)) await download('https://raw.githubusercontent.com/uploader762/dat3/main/uploads/70b790-1776550169070.png', crossPath)
FontLibrary.use('rog', [font1])
FontLibrary.use('glow', [font2])
class BALogo {
graphOffset
paddingX = 10
horizontalTilt = -0.4
textBaseLine = 0.68
fontSize
canvasHeight = 250
canvasWidth = 900
canvasWidthL = this.canvasWidth / 2
canvasWidthR = this.canvasWidth / 2
textWidthL = 0
textWidthR = 0
textMetricsL = null
textMetricsR = null
transparentBg
font
fontFamily = 'rog'
hollowPath = [
[284, 136],
[321, 153],
[159, 410],
[148, 403]
]
constructor({ options = {}, config }) {
this.fontSize = options.fontSize || config.fontSize
this.transparentBg = options.transparent ? !config.transparent : config.transparent
this.graphOffset = {
X: options.haloX || config.haloX,
Y: options.haloY || config.haloY
}
this.font = `${this.fontSize}px ${this.fontFamily}`
}
async draw({ textL, textR }) {
const canvas = new Canvas(this.canvasWidth, this.canvasHeight)
const ctx = canvas.getContext('2d')
const halo = await loadImage(haloPath)
const cross = await loadImage(crossPath)
ctx.font = this.font
this.textMetricsL = ctx.measureText(textL)
this.textMetricsR = ctx.measureText(textR)
this.textWidthL =
this.textMetricsL.width -
(this.textBaseLine * this.canvasHeight + this.textMetricsL.fontBoundingBoxDescent) * this.horizontalTilt
this.textWidthR =
this.textMetricsR.width +
(this.textBaseLine * this.canvasHeight - this.textMetricsR.fontBoundingBoxAscent) * this.horizontalTilt
this.canvasWidthL = Math.max(this.canvasWidth / 2, this.textWidthL + this.paddingX)
this.canvasWidthR = Math.max(this.canvasWidth / 2, this.textWidthR + this.paddingX)
const finalCanvas = new Canvas(this.canvasWidthL + this.canvasWidthR, this.canvasHeight)
const ctxFinal = finalCanvas.getContext('2d')
if (!this.transparentBg) {
ctxFinal.fillStyle = '#ffffff'
ctxFinal.fillRect(0, 0, finalCanvas.width, finalCanvas.height)
}
const center = this.canvasWidthL
const y = finalCanvas.height * this.textBaseLine
ctxFinal.setTransform(1, 0, this.horizontalTilt, 1, 0, 0)
ctxFinal.fillStyle = '#128AFA'
ctxFinal.textAlign = 'end'
ctxFinal.font = this.font
ctxFinal.fillText(textL, center, y)
ctxFinal.setTransform(1, 0, 0, 1, 0, 0)
const gx = center - this.canvasHeight / 2 + this.graphOffset.X
const gy = this.graphOffset.Y
ctxFinal.drawImage(halo, gx, gy, this.canvasHeight, this.canvasHeight)
ctxFinal.setTransform(1, 0, this.horizontalTilt, 1, 0, 0)
ctxFinal.textAlign = 'start'
ctxFinal.lineWidth = 12
ctxFinal.strokeStyle = '#ffffff'
ctxFinal.fillStyle = '#2B2B2B'
ctxFinal.font = this.font
ctxFinal.strokeText(textR, center, y)
ctxFinal.fillText(textR, center, y)
ctxFinal.setTransform(1, 0, 0, 1, 0, 0)
ctxFinal.beginPath()
ctxFinal.moveTo(gx + (this.hollowPath[0][0] / 500) * this.canvasHeight, gy + (this.hollowPath[0][1] / 500) * this.canvasHeight)
for (let i = 1; i < 4; i++) {
ctxFinal.lineTo(gx + (this.hollowPath[i][0] / 500) * this.canvasHeight, gy + (this.hollowPath[i][1] / 500) * this.canvasHeight)
}
ctxFinal.closePath()
ctxFinal.fillStyle = '#ffffff'
ctxFinal.fill()
ctxFinal.drawImage(cross, gx, gy, this.canvasHeight, this.canvasHeight)
return finalCanvas.toBuffer('png')
}
}
let handler = async (m, { conn, text, command }) => {
try {
if (!text) return m.reply(`*Example :* .${command} Blue|Arcive`)
if (!text.includes('|')) return m.reply('Format Salah Semua Harus Terisi yah')
const [l, r] = text.split('|')
if (!l || !r) return m.reply('Format Salah Semua Harus Terisi yah')
m.reply(global.wait)
const buffer = await new BALogo({
config: {
fontSize: 84,
transparent: false,
haloX: -15,
haloY: 0
}
}).draw({
textL: l.trim(),
textR: r.trim()
})
await conn.sendMessage(m.chat, { image: buffer }, { quoted: m })
} catch (e) {
m.reply(e.message)
}
}
handler.help = ['balogo', 'bluearchivelogo']
handler.command = ['balogo', 'bluearchivelogo']
handler.tags = ['maker']
export default handler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment