npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rendercord

v1.1.2

Published

InstaCord node-canvas-based rendering plugin

Downloads

1

Readme

rendercord

InstaCord renderer module. Draws images or animations, then serves them to discord.

Installation

npm install rendercord

Usage

Include the script as middleware

.middleware(require('rendercord')())

It then exposes actions.render (see full example script below)

Rendercord does not magically bypass the preview upload limit of 10mb, so don't make movie-length animations with it. Please be aware that this is not built-in middleware, and you can't load it using discord.mw('rendercord')().

Example code, which draws a red square moving from the top left to the bottom right:

const Discord = require("instacord");
const discord = new Discord();

discord
  .login(require('./secret.js'))
  .prefix("-")
  // Require the renderer middleware
  .middleware(require('rendercord')())
  // Command usage: '-render'
  .on('render', (actions, substr, storage) => {
    actions.log("Render image!");
    // Don't forget to return the promise!
    return actions.render({
      fps:     30, // The output framerate
      frames: 125, // The total frame count to render
      width:  400, // The output dimensions
      height: 300,
      quality: 100, // the jpeg quality. Default 100, you should probably leave this alone.
      buffer: 4096, // the output buffer size. Default 4096, you should probably leave this alone.
      animated: true, // If you don't use this, it'll just be a jpeg!
      jpegStream: true // default: true. Using a jpegStream is *much* faster than a pngStream, but you get jpeg.
    }, (canvas, frame) => {
      canvas.clearRect(0, 0, 400, 300);
      canvas.fillStyle = 'red';
      canvas.fillRect(frame/120 * 400, frame/120 * 300, 20, 20);
    }).then(() => {
      // Done! The image was automatically uploaded to discord.
    })
  })

  // Example of saving and loading the canvas
  // We'll store the frame in the db
  .database('rendercord-example')
  .middleware(discord.mw('db.loadKey')('lastFrame'))
  .on(/rect|cube|square/, (actions, substr, storage) => {
    actions.log("Render cubes!");
    return actions.render({
      source: storage.lastFrame, // Load an image as the first frame. Default: null,
      fit: true, // Fits the source to the canvas size. Default: false,
      animated: false,
      width:  200,
      height: 150
    }, (canvas, frame) => {
      // You can also load an image this way. Second value is fit.
      canvas.load(storage.lastFrame, false);

      var colors = [ 'red', 'orange', 'yellow', 'green', 'blue', 'indigo' ]
      canvas.fillStyle = colors[Math.floor(Math.random()*colors.length)];
      var dims = [
        Math.random()*200,
        Math.random()*150,
        Math.random()*10+5,
        Math.random()*10+5
      ];
      canvas.fillRect(...dims);

      // canvas.save() returns a buffer. Don't overuse this because it
      // always saves as a PNG, which is far slower than the default renderer.
      storage.lastFrame = canvas.save();

      // Let's highlight the most recent rectangle, *after* saving it!
      canvas.strokeStyle = 'white';
      canvas.lineWidth = 2;
      canvas.strokeRect(...dims);
    })
  })