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

pngjs-draw-react-native

v0.1.6

Published

Adds basic drawing functionnalities to pngjs. Originally created by Aloïs Deniel

Downloads

5

Readme

node-pngjs-draw

Adds basic drawing functionnalities to pngjs node module.

Install

$ npm install --save pngjs-draw

Example

var fs = require('fs');
var drawing = require('pngjs-draw');
var png = drawing(require('pngjs').PNG);

fs.createReadStream("blue.png")
  .pipe(new png({ filterType: 4 }))
  .on('parsed', function() {
    // Draws a pixel with transparent green
    this.drawPixel(150,200, this.colors.black())

    // Draws a line with transparent red
    this.drawLine(0,0,200,200, this.colors.red(50))

    // Draws a rectangle with transparent black
    this.fillRect(150,150,75,20, this.colors.black(100))

    // Draws a filled rectangle with transparent white
    this.fillRect(50,50,100,100, this.colors.white(100))

    // Draws a text with custom color
    this.drawText(20,20, "Hello world !", this.colors.new(255,100,10))

    // Writes file
    this.pack().pipe(fs.createWriteStream('blue.out.png'));
  });

Documentation

PNG.prototype.drawPixel

Draws the pixel at the given coordinates with the given color.

  • {int} x The x coordinate of the pixel
  • {int} y The y coordinate of the pixel
  • {Array(byte)} color The color used to paint the pixel

PNG.prototype.drawLine

Draws a line beetween two points with the given color.

  • {int} x0 The x coordinate of the start
  • {int} y0 The y coordinate of the start
  • {int} x1 The x coordinate of the end
  • {int} y1 The y coordinate of the end
  • {Array(byte)} color The color used to paint the line

PNG.prototype.drawRect

Draws a stroked rectangle with the given color.

  • {int} x The top left x coordinate of the rectangle
  • {int} y The top left y coordinate of the rectangle
  • {int} width The width of the rectangle
  • {int} height The height of the rectangle
  • {Array(byte)} color The color used to paint strokes of the rectangle

PNG.prototype.fillRect

Draws a filled rectangle with the given color.

  • {int} x The top left x coordinate of the rectangle
  • {int} y The top left y coordinate of the rectangle
  • {int} width The width of the rectangle
  • {int} height The height of the rectangle
  • {Array(byte)} color The color used to fill the rectangle

PNG.prototype.drawText

Draw a text to the image.

  • {int} x The top left x coordinate of the string
  • {int} y The top left y coordinate of the string
  • {string} text The string value
  • {Array(byte)} color The color used used as foreground
  • {Object} font The font used to render the string (optional)
  • {Object} text The string value

return {int} The length in pixel of the rendered string

PNG.prototype.measureString

Measure the rendered text length with the given font.

  • {string} text The string value
  • {Array(byte)} color The color used used as foreground
  • {Object} font The font used to render the string (optional)

return {int} The length in pixel of the rendered string

Creating colors

[<R>,<G>,<B>,<A>]

A color is a javascript array containing Red/Green/Blue/Alpha byte components.

PNG.prototype.colors.new = function(r,g,b,a)

The new method generates an array with the provided components.

Default values :

  • r: 0
  • g: 0
  • b: 0
  • a: 255
PNG.prototype.colors.red = function(a)
PNG.prototype.colors.greed = function(a)
PNG.prototype.colors.blue = function(a)
PNG.prototype.colors.black = function(a)
PNG.prototype.colors.white = function(a)

Helper methods for creating base colors are also available.

Custom fonts

In order to use a custom font, you must first generate a font module from an image presenting all the supported characters.

For more details, take a look at these files :

  • build-font.js
  • fonts/*
  • custom-font/*

Roadmap / Ideas

  • More shapes (circles, polygons)
  • Rotations
  • Multi-lines texts

Copyright and license

MIT © Aloïs Deniel