npm.io
1.1.0 • Published 3d ago

fakedev

Licence
MIT
Version
1.1.0
Deps
1
Size
4.9 MB
Vulns
0
Weekly
0

fakedev

Generator PLP (Profile Logo Picture) berbasis Canvas untuk Node.js.

Hasil berupa PNG Buffer yang berisi:

  • Foto profil bulat
  • Nama melengkung (⌣) di atas, dengan opsi role/jabatan kecil di bawahnya
  • Badge centang
  • Background yang dapat dipilih (termasuk mode acak)

Package ini 100% platform-agnostic. Tidak memiliki kode khusus Telegram, WhatsApp, Discord, maupun framework bot lainnya. Output hanya berupa Buffer, sehingga bisa digunakan di project Node.js apa pun.


Install

npm install fakedev

Assets

Struktur default:

assets/
├── background1.jpg
├── background2.jpg
├── background3.jpg
├── centang.png
└── font.ttf
File Required Keterangan
background{N}.jpg Background PLP
centang.png Badge centang
font.ttf Font custom

Basic Usage

const { generatePLP } = require("fakedev");
const fs = require("fs");

(async () => {
  const image = await generatePLP({
    photo: "./photo.jpg",
    name: "Kyuuu",
    bgIndex: 1,
    textColor: "#FFFFFF",
    shadowColor: "#00ffff",
    checkSize: 220
  });

  fs.writeFileSync("result.png", image);
})();

Nama + Role ("Nama|Role")

Nama besar selalu di atas (melengkung). Mulai versi ini, kamu bisa menambahkan baris role/jabatan kecil tepat di bawah nama, cukup pisahkan dengan karakter |:

const image = await generatePLP({
  photo: "./photo.jpg",
  name: "Kyuu|Not Dev", // "Kyuu" jadi nama besar, "Not Dev" jadi role di bawahnya
  bgIndex: 1
});

Format ini fleksibel, contoh lain: "text|text2", "Sanaka|Owner", "Alya|Bot Developer".

Kalau tidak butuh format "Nama|Role", role juga bisa diisi terpisah lewat opsi role:

const image = await generatePLP({
  photo: "./photo.jpg",
  name: "Kyuu",
  role: "Not Dev",
  bgIndex: 1
});

Tidak menulis role sama sekali (baik lewat "|" maupun opsi role) tetap didukung — hasilnya sama seperti versi sebelumnya, hanya nama tanpa role.


Pilih Background

bgIndex mendukung tiga cara:

// 1) Pilih background tertentu lewat nomor file (assets/background5.jpg)
await generatePLP({ photo, name, bgIndex: 5 });

// 2) Pilih acak dari semua background yang ada di assetsDir
await generatePLP({ photo, name, bgIndex: "random" }); // atau "acak"

// 3) Default kalau tidak diisi -> bgIndex: 1
await generatePLP({ photo, name });

Kalau index yang diminta tidak ada filenya, generatePLP akan melempar error yang menyebutkan daftar index background yang valid, supaya gampang di-debug.

Untuk bikin menu pilih background sendiri (misalnya tombol interaktif di bot), ambil daftar index yang tersedia lewat:

const { listAvailableBackgrounds } = require("fakedev");
const indexes = listAvailableBackgrounds("./assets"); // contoh: [1, 2, 3, ..., 30]

Options

Option Type Default Description
photo string | Buffer required Path lokal, URL, atau Buffer foto.
name string required Nama yang ditampilkan. Bisa berupa "Nama|Role" untuk sekaligus mengisi role.
role string "" Role/jabatan kecil di bawah nama. Diabaikan kalau name sudah mengandung "|".
bgIndex number | "random" 1 Background yang digunakan, atau "random"/"acak" untuk acak.
textColor string #FFFFFF Warna teks nama.
shadowColor string #00ffff Warna glow/shadow (dipakai untuk nama & role).
roleColor string sama dengan textColor Warna teks role.
assetsDir string ./assets Folder assets custom.
checkSize number 220 Ukuran badge centang.

Color Presets

const {
  textColors,
  shadowColors
} = require("fakedev");

console.log(textColors.white);
console.log(shadowColors.cyan);

Tersedia lebih dari 90 preset warna untuk teks dan glow.


WhatsApp (Baileys)

const { generatePLP } = require("fakedev");

const buffer = await generatePLP({
  photo: photoBuffer,
  name: "Kyuuu|Not Dev",
  bgIndex: "random"
});

await sock.sendMessage(chatId, {
  image: buffer
});

Telegram (Telegraf)

const { generatePLP } = require("fakedev");

const buffer = await generatePLP({
  photo: photoUrl,
  name: "Kyuuu|Owner"
});

await ctx.replyWithPhoto({
  source: buffer
});

node-telegram-bot-api

const { generatePLP } = require("fakedev");

const buffer = await generatePLP({
  photo: photoUrl,
  name: "Kyuuu"
});

await bot.sendPhoto(chatId, buffer);

API

const { generatePLP, listAvailableBackgrounds } = require("fakedev");

generatePLP(options)

Mengembalikan:

Promise<Buffer>

Output berupa PNG Buffer yang siap digunakan untuk:

  • WhatsApp Bot
  • Telegram Bot
  • Discord Bot
  • Express API
  • Fastify API
  • Next.js API Routes
  • Vercel Functions
  • Node.js Project

listAvailableBackgrounds(assetsDir)

Mengembalikan array nomor index background yang tersedia di assetsDir, contoh: [1, 2, 3, ..., 30]. Berguna untuk membuat menu pilih background sendiri (tombol interaktif, dsb).


License

MIT

Keywords