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 🙏

© 2025 – Pkg Stats / Ryan Hefner

lw.raster-to-gcode

v0.6.3

Published

Raster to GCode for LaserWeb

Readme

lw.raster-to-gcode

Raster to G-Code for LaserWeb/CNCWeb.

Demo

https://lautr3k.github.io/lw.raster-to-gcode/dist/example/

Installation

Using NPM

npm install lw.raster-to-gcode

Using GIT

git clone https://github.com/lautr3k/lw.raster-to-gcode.git
cd lw.raster-to-gcode
npm install

Or download the last build from https://raw.githubusercontent.com/lautr3k/lw.raster-to-gcode/master/dist/lw.raster-to-gcode.js

<script src="./lw.raster-to-gcode.js"></script>
<script>
  var rasterToGcode = RasterToGcode.RasterToGcode();
</script>

Settings

let settings = {
    ppi: { x: 254, y: 254 }, // Pixel Per Inch (25.4 ppi == 1 ppm)

    toolDiameter: 0.1,      // Tool diameter in millimeters
    rapidRate   : 1500,     // Rapid rate in mm/min (G0 F value) nullish value to disable
    feedRate    : 500,      // Feed rate in mm/min (G1 F value)
    rateUnit    : 'mm/min', // Rapid/Feed rate unit [mm/min, mm/sec]

    beamRange: { min: 0, max: 1 },   // Beam power range (Firmware value)
    beamPower: { min: 0, max: 100 }, // Beam power (S value) as percentage of beamRange

    milling  : false, // EXPERIMENTAL
    zSafe    : 5,     // Safe Z for fast move
    zSurface : 0,     // Usinable surface (white pixels)
    zDepth   : -10,   // Z depth (black pixels)
    passDepth: 1,     // Pass depth in millimeters

    offsets  : { X: 0, Y: 0 }, // Global coordinates offsets
    trimLine : true,           // Trim trailing white pixels
    joinPixel: true,           // Join consecutive pixels with same intensity
    burnWhite: true,           // [true = G1 S0 | false = G0] on inner white pixels
    verboseG : false,          // Output verbose GCode (print each commands)
    diagonal : false,          // Go diagonally (increase the distance between points)

    precision: { X: 2, Y: 2, S: 4 }, // Number of decimals for each commands

    nonBlocking: true, // Use setTimeout to avoid blocking the UI

    filters: {
        smoothing   : 0,      // Smoothing the input image ?
        brightness  : 0,      // Image brightness [-255 to +255]
        contrast    : 0,      // Image contrast [-255 to +255]
        gamma       : 0,      // Image gamma correction [0.01 to 7.99]
        grayscale   : 'none', // Graysale algorithm [average, luma, luma-601, luma-709, luma-240, desaturation, decomposition-[min|max], [red|green|blue]-chanel]
        shadesOfGray: 256,    // Number of shades of gray [2-256]
        invertColor : false   // Invert color...
    },

    onProgress       : null, // On progress callbacks
    onProgressContext: null, // On progress callback context

    onDone       : null, // On done callback
    onDoneContext: null, // On done callback context

    onAbort       : null, // On abort callback
    onAbortContext: null  // On abort callback context
}

Usages

import RasterToGcode from 'lw.raster-to-gcode'

// Create RasterToGcode object
let rasterToGcode = new RasterToGcode(settings)

// Register events callbacks
rasterToGcode.on('progress', function(event) {
    console.log('onProgress:', event); // event = { gcode, percent }
})
.on('done', function(event) {
    console.log('onDone:', event); // event = { gcode }
});

// <file> can be Image, File URL object or URL string (http://* or data:image/*)
rasterToGcode.load(file).then(function(rtg) {
    console.log('rasterToGcode:', rtg); // rtg === rasterToGcode
    rasterToGcode.run(); // Return gcode array if nonBlocking = false
})
.catch(function(error) {
    console.error('error:', error);
});