Giter VIP home page Giter VIP logo

canvacord's Introduction

SWUbanner

Canvacord

Easily generate images on-the-fly with node.js using wide range of templates.

Warning

You are looking at the next version of canvacord, which is under development. Go to the main branch to view legacy codebase.

Features

Coming Soon!

Contributing

About the project

Unlike previous versions, this project internally uses react-like elements (JSX) to generate an image with the help of satori, without depending upon canvas libraries. Internally, there exists a concept of Nodes which are basically components for canvacord template. The root node is known as a template. Templates are dynamic, which makes it easier to customize each and every part of the image you are generating. You can follow the example below to add your own components/templates to this library:

Adding custom template and node

import { JSX, Node, Builder } from "canvacord";

// JSX refers to JSX factory
// Builder refers to template builder
// Node refers to component base

class TextNode extends Node<{
  data: string;
  color: string;
}> {
  /*
   * Visual representation of this node
   */
  public toElement() {
    return (
      <h1
        style={{
          color: this.getProperty("color"),
        }}
      >
        {this.getProperty("data")}
      </h1>
    );
  }
}

class ProfileCard extends Builder {
  public setUsername(name: string, color: string) {
    const node = new TextNode({
      data: name,
      color,
    });

    super.addComponent(node);
  }

  public render() {
    // return root layout along with components
    return (
      <div
        style={{
          width: `${this.width}px`,
          height: `${this.height}px`,
          display: "flex",
          alignItems: "center",
          justifyContent: "center",
          backgroundColor: "#1A1A23",
        }}
      >
        {/* Render all of the components in the canvas */}
        {this.components.map((component) => {
          return component.toElement();
        })}
      </div>
    );
  }
}

canvacord's People

Contributors

twlite avatar notunderctrl avatar abh80 avatar sksmta avatar 21z avatar itsauric avatar mittelblut9 avatar damien111 avatar sansekai avatar samiul30 avatar shashank3736 avatar tes-balo avatar zyrouge avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.