Get Started with Node.js
You can use Spacha even from server side.
caution
Quick Start
Prepare
- Windows
- Mac
- Linux
Download installer from nodejs.org
Google with this term.
mac nodejs install
Google with this term.
[distro name] nodejs install
Prepare
sample-spc-node
directory.mkdir -p sample-spc-node
cd sample-spc-nodeGenerate
package.json
npm init --yes
Install Spacha and necessary package
npm i spacha canvas
Prepare
index.js
index.jsconst Canvas = require("canvas");
const Image = Canvas.Image;
const { SpachaImage } = require("spacha");
const fs = require("fs");
(async () => {
const canvas = new Canvas.Canvas(600, 300);
const ctx = canvas.getContext("2d");
const iconImg = new Image;
iconImg.src = "https://github.com/bonychops.png";
await new Promise((resolve) => { iconImg.onload = resolve });
new SpachaImage(ctx, {
user: {
name: "Bony_Chops",
img: iconImg
},
price: -31117,
theme: "red"
});
saveImg(canvas);
})();
const saveImg = (canvas) => {
const b64 = canvas.toDataURL().split(",")[1];
const buf = Buffer.from(b64, 'base64');
fs.writeFileSync("spc.png", buf);
}Execute it to generate
spc.png
.node index
This is the real total balance of Bony_Chops in 09/17/2022
Samples
See samples at here.