Skip to content

Datamosh-js/datamosh

Repository files navigation

Datamosh License: MIT code style: prettier Build Status

datamosh_cover_2x

Mess around with image data using buffers, create some interesting & artistic results, profit.

Install

$ npm install datamosh

Usage

const mosh = require("datamosh");

let imgBuff = await readFile("/full/path/to/image.png");

let moshedBuff = await mosh(imgBuff, "vaporwave");

Reading/Writing the moshed image

mosh("~/image.png", null, "~/moshed_image.png");

// because mode is null, a random mode will be chosen

Moshing a buffer with callbacks

const cb = (err, data) => {
  if (!err) writeFile("/path/to/out.gif", data);
};

mosh(imgBuff, "vana", cb);

Using multiple modes on a single image, applied with respect to order.

let moshedBuff = await mosh(imgBuff, ["fatcat", "vaporwave", "walter"]);

// ['vana', null, null] is also valid => ['vana', random, random]

API

mosh(source, mode?, cb|writePath?)

Takes input source Buffer/Path, returns an encoded Buffer with the applied modes.

  • mode, the mosh mode to apply to the source image. Multiple modes may be passed using an array of modes. Any null values are replaced with a random mode.
  • cb (err, data), when using callbacks.
  • writePath, the path to write the moshed image to.

Paths may use the tilde (~) character. Datamosh validates read and write paths, replacing tilde with the path to the home directory.

~/Desktop/moshes/ -> /home/youruser/Desktop/moshes

Custom Modes

Datamosh allows you to set custom moshing modes. As of v1.1.0, this may be acomplished by adding a mosh function to the MODES property.

For mosh function starter code, see the included template file located here.

const datamosh = require("datamosh");

function newMode(data, width, height) {
  // your cool code goes here!

  return data;
}

datamosh.MODES.newMode = newMode;

Example Images

mode:fatcat Fatcat was created by user @mster

mode:vaporwave Vaporwave was created by user @tlaskey

mode:blurbobb

mode:veneneux

Datamosh in the wild

Check out this list of awesome apps that use datamosh!