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

editor-canvas

v0.2.3

Published

Easy to edit image (resize, circle, curve, polygon and crop)

Downloads

780

Readme

Easy to edit image.

Installation

Install editor-canvas

$ npm install editor-canvas

Features

What's new!!

New function

update image function(s)

  • image width/height will not change !
  • new parameter (Canvas) to easy to use.

Description

editor canvas is a simple package help you to edit your image and text. (All example bellow is under discord, but you can use the function anywhere)

resizeText

Resize text to not go out canvas image.

const Discord = require("discord.js");
const client = new Discord.Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES,
  ],
});
const Canvas = require("canvas");
const editor = require("editor-canvas");

client.on("messageCreate", async (message) => {
  var args = message.content.split(" ");
  if (args[0].toLowerCase() === "write") {
    var canvas = Canvas.createCanvas(512, 512),
      ctx = canvas.getContext("2d");

    var words = args.slice(1);
    ctx.font = editor.resizeText(ctx, { text: words });
    ctx.fillText(words, 100, 0);

    message.channel.send({ files: [canvas.toBuffer()] });
  }
});

splitText

Split text to not go out canvas image.

const Discord = require("discord.js");
const client = new Discord.Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES,
  ],
});
const Canvas = require("canvas");
const editor = require("editor-canvas");

client.on("messageCreate", async (message) => {
  var args = message.content.split(" ");
  if (args[0].toLowerCase() === "write") {
    var canvas = Canvas.createCanvas(512, 512),
      ctx = canvas.getContext("2d");

    var words = args.slice(1);
    ctx.font = "20px ";
    words = editor.splitText(ctx, { text: words });
    ctx.fillText(words, 100, 0);

    message.channel.send({ files: [canvas.toBuffer()] });
  }
});

drawCenter

draw image in a specify center point

const Discord = require("discord.js");
const client = new Discord.Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES,
  ],
});
const Canvas = require("canvas");
const editor = require("editor-canvas");

client.on("messageCreate", async (message) => {
  var args = message.content.split(" ");
  if (args[0].toLowerCase() === "center") {
    var canvas = Canvas.createCanvas(512, 512),
      ctx = canvas.getContext("2d");

    var avatar = message.author.displayAvatarURL({
      dynamic: false,
      format: "jpg",
      size: 1024,
    });

    avatar = await editor.drawCircle({ image: avatar, Canvas });
    editor.drawCenter(ctx, avatar, 200, 200, 100, 100);

    message.channel.send({ files: [canvas.toBuffer()] });
  }
});

drawCircle

from an image to circle.

const Discord = require("discord.js");
const client = new Discord.Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES,
  ],
});
const editor = require("editor-canvas");

client.on("messageCreate", async (message) => {
  if (message.content === "circle") {
    var avatar = message.author.displayAvatarURL({
      dynamic: false,
      format: "jpg",
      size: 2048,
    });

    avatar = await editor.drawCircle({ image: avatar });

    message.channel.send({ files: [avatar] });
  }
});

drawSquare

Curve the edge for image

const Discord = require("discord.js");
const client = new Discord.Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES,
  ],
});
const editor = require("editor-canvas");

client.on("messageCreate", async (message) => {
  if (message.content === "curve") {
    var avatar = message.author.displayAvatarURL({
      dynamic: false,
      format: "jpg",
      size: 1024,
    });

    avatar = await editor.drawSquare({ image: avatar });

    message.channel.send({ files: [avatar] });
  }
});

drawPolygon

Draw any polygon with simple step

const Discord = require("discord.js");
const client = new Discord.Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES,
  ],
});
const editor = require("editor-canvas");

client.on("messageCreate", async (message) => {
  if (message.content === "polygon") {
    var avatar = message.author.displayAvatarURL({
      dynamic: false,
      format: "jpg",
      size: 1024,
    });

    avatar = await editor.drawPolygon({ image: avatar, angle: 10 });

    message.channel.send({ files: [avatar] });
  }
});

resizeImage

Resize your image with specific width & height

const Discord = require("discord.js");
const client = new Discord.Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES,
  ],
});
const editor = require("editor-canvas");

client.on("messageCreate", async (message) => {
  var [cmd, width, height] = message.content.trim().split(/ +/);
  if (cmd === "resize") {
    var avatar = message.author.displayAvatarURL({
      dynamic: false,
      format: "jpg",
      size: 1024,
    });

    avatar = await editor.resizeImage({
      image: avatar,
      width: width,
      height: height,
    });

    message.channel.send({ files: [avatar] });
  }
});

New

cropImage

crop your image with specific coordinates

const Discord = require("discord.js");
const client = new Discord.Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES,
  ],
});
const editor = require("editor-canvas");

client.on("messageCreate", async (message) => {
  var [cmd, x, y, width, height] = message.content.trim().split(/ +/);
  if (cmd === "crop") {
    var avatar = message.author.displayAvatarURL({
      dynamic: false,
      format: "jpg",
      size: 1024,
    });

    avatar = await editor.cropImage({
      image: avatar,
      x: x,
      y: y,
      width: width,
      height: height,
    });

    message.channel.send({ files: [avatar] });
  }
});

Other

functions and its options.

resizeText


• (ctx, { text, width, font })

text // specific text. (required)

width // when text go out the spefic width  will resize. (optional)
// width: 200

font // text font to start with it. (optional)
// font: 20

splitText


• (ctx, { text, width, maxLine })

text // specific text. (required)

width // when text go out the spefic width  will resize. (optional)
// width: 200

maxLine // max line reached when text is big. (optional)
// maxLine: 2

drawCircle


• ({ image ,fill, stroke, weight, Canvas })

image // specific image. (optional)

fill // if don't want image , u can draw circle with specific color. (optional)
// fill: "BLACK"

stroke // draw a fram among image or circle, with specific color. (optional)
// stroke: "BLACK"

weight // fram width. (optional)
//weight: 5

Canvas // you can use the image in your canvas code without use "loadImage"
// else will be a Buffer image

drawSquare


• ({ image, fill, stroke, weight, curve, Canvas })

image // specific image. (optional)

fill // if don't want image , u can draw circle with specific color. (optional)
// fill: "BLACK"

stroke // draw a fram among image or circle, with specific color. (optional)
// stroke: "BLACK"

weight // fram width. (optional)
//weight: 5

curve // curve the edge. (optional)
//curve: 30

Canvas // you can use the image in your canvas code without use "loadImage"
// else will be a Buffer image

drawPolygon


• ({ image, fill, stroke, weight, angle })

image // specific image. (optional)

fill // if don't want image , u can draw circle with specific color. (optional)
// fill: "BLACK"

stroke // draw a fram among image or circle, with specific color. (optional)
// stroke: "BLACK"

weight // fram width. (optional)
//weight: 5

angle // count of polygon angle. (optional)
//angle: 10

Canvas // you can use the image in your canvas code without use "loadImage"
// else will be a Buffer image

resizeImage


• ({ image, width, height, Canvas })

image // specific image. (required)

width // the new width for image. (optional)

height // the new height for image. (optional)

Canvas // you can use the image in your canvas code without use "loadImage"
// else will be a Buffer image

cropImage


• ({ image, x, y, width, height, Canvas })

image // specific image. (required)

x // to crop from top

y // to crop from left

width // the width to crop

height // the height to crop

Canvas // you can use the image in your canvas code without use "loadImage"
// else will be a Buffer image

Thanks for using it ❤️. Support