JSPM

  • Created
  • Published
  • Downloads 38
  • Score
    100M100P100Q66820F
  • License BSD 3-Clause

Canvas Builder

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ness-canvas) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    Ness-Canvas

    npm version

    Ness-Canvas is a small canvas Builder for Canvas.

    Inslallation

    $ npm install ness-canvas

    If you are not used to canvas, the latter can request a specific installation that you will find here

    Quick Example

    const { NessBuilder } = require('ness-canvas')
    const { loadImage } = require('canvas')
    
    const background = await loadImage('https://media.discordapp.net/attachments/1006600590408818810/1006600665298116728/background-3147808.jpg');
    const avatar = await loadImage('https://media.discordapp.net/attachments/758031322244710601/1000153437813616650/perso_anime_U565bW7EhY2InkF.png');
    
    const builder = new NessBuilder(700, 250) // Set Image format
      .setCornerRadius(15) // round the edges of the image
      .setBackground(background) // Add Background
      .setFrame("Square", { x: 25, y:25 }, { widht: 150, height: 150 }, { radius: 15, content: {imageOrText: avatar}}) // Add image in a square frame
      .setFrame("Polygones", { x: 550, y:25 }, { widht: 130, height: 130 }, {radius: 6, content: { imageOrText: 33, textOptions: { font: "sans-serif", size: 80, color: "#000000", textAlign: "center", textBaseline: "middle" }}}) // Write "33" in a polygones frame
      .setExp({x: 45, y: 200}, {width: 655, height: 30}, 20, 65) // Draw an experience bar
      .setText('Hello World!', {x:350, y:100}, {size: 40, font: 'Impact'}) // Write "Hello World!"
    
    
      // Generate canvas in a specific file
      builder.generateTo('FileLocation', 'ImageName', "PNG | JPEG | JPG")
    
      // Recover the canvas buffer
      Builder.getBuffer()

    Result

    alt text