Skip to content

Commit

Permalink
Merge v1.4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
mster committed May 17, 2021
2 parents 9bbfe0f + 27d3efa commit fcd1189
Show file tree
Hide file tree
Showing 13 changed files with 400 additions and 2,369 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: node_js
node_js:
- 8
- 10
- 12
- 14
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Follow the [Getting Started](#getting-started) guide if you're new to this.

## Code Style

Datamosh uses [StandardJS](https://standardjs.com/). To have your contributions accepted, they must also be in StandardJS style.
Datamosh uses [Prettier](https://prettier.io/). To have your contributions accepted, they must also be in StandardJS style.

To test if your code passes, run the test command:
`npm run lint`
Expand All @@ -57,7 +57,7 @@ To test if your code passes, run the test command:

As of v1.0.0, tests consist of:

- linting using StandardJS
- linting using Prettier

## Need Help

Expand Down
142 changes: 50 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,130 +1,88 @@
# Datamosh
# Datamosh [![License: MIT](https://img.shields.io/badge/license-MIT-blue)](https://opensource.org/licenses/MIT) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier) [![Build Status](https://travis-ci.com/mster/datamosh.svg?branch=master)](https://travis-ci.com/mster/datamosh)

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

## API
![datamosh_cover_2x](https://user-images.githubusercontent.com/15038724/118436128-12662b00-b695-11eb-8b9e-f4d91a869adf.png)

### mosh ( options, cb )

- `options`:
Mess around with image data using _buffers_, create some interesting & artistic results, **profit**.

- `read`: `<string>` | `<Buffer>` (Required)
# Install

May be a string path to original supported image, or the Buffer of said image.
```
$ npm install datamosh
```

Supported image types: `.jpg, .jpeg, .png, .bmp, .tiff, .gif`.
# Usage

- `write`: `<string>`
Using callbacks

Path to write the resulting image.
```js
const mosh = require("datamosh");

If unspecified, the resulting image data will be returned as a Buffer.
const opts = {
read: "path/to/file/in.ext",
mode: "fatcat",
};

- `mode`: `<string>`
const cb = (err, moshedBuffer) => {
if (!err) writeFile("path/to/file/out.ext", moshedBuffer);
};

The mode to choose when moshing the supplied image. If no mode is specified, it will be chosen at random.
mosh(opts, cb);
```

Current modes include:
`schifty`, `blurbobb`, `veneneux`, `vana`, `fatcat`.
Using async/await

- `cb`: `function(error, data)`
```js
const { promisify } = require("util");

The callback function, as `datamosh` is callback based.
const promisifiedMosh = promisify(mosh);

The image `data` will be returned as a Buffer if `options.write` is unspecified. Reference the following for examples on usage.
const imgBuffer = await promisifiedMosh(opts);
```

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

```js
/*
Using paths
*/
;(function jumpInThePit () {
require('datamosh')(
{
read: '/path/to/read/in.gif',
write: '/path/to/write/out.gif',
mode: 'veneneux'
},
err => {
if (err) return console.error(err)

console.log('Moshing Completed!')
}
)
})()

/*
Using buffers directly
*/
;(function boogieWoogieBuffer () {
// can be done w/ async too!
let read = require('fs').readFileSync
let write = require('fs').writeFileSync

let img = read('/path/to/read/in.jpg')
require('datamosh')(
{
read: img
},
(err, moshedImg) => {
if (err) return console.error(err)

console.log('Moshing Completed!')
write('/path/to/write/out.jpg', moshedImg)
}
)
})()
const opts = {
read: "path/to/file/in.ext",
mode: ["vaporwave", "fatcat", "vana"],
};
```

## Custom Modes
# 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](https://github.com/mster/datamosh/blob/master/lib/modes/template).

```js
/*
Setting custom modes
*/
const datamosh = require('datamosh')
function myNewMode (image) {
// actually does nothing to the image
return image
}
const datamosh = require("datamosh");

datamosh.MODES.myNewMode = myNewMode
datamosh(/* ... */)
```
function myNewMode(image) {
const bitmap = image.bitmap.data;
// your cool code goes here

## Datamosh in the wild
image.bitmap.data = bitmap;

Check out this list of awesome apps that use `datamosh`!
return image;
}

- [JanMichaelBot](https://github.com/tlaskey/JanMichaelBot) by user [@Tlaskey](https://github.com/tlaskey)
datamosh.MODES.myNewMode = myNewMode;
```

## Example Images

**Original**

![cute_kibby](https://user-images.githubusercontent.com/15038724/63730272-7bea3a00-c81f-11e9-9180-15d0d983adaf.jpg)

**_Moshed_** using `schifty`.
![mode:fatcat](https://user-images.githubusercontent.com/15038724/118332090-64088d00-b4be-11eb-8d6e-139174c5d3ab.png)
Fatcat was created by user [@mster](https://github.com/mster)

![moshed_kibby](https://user-images.githubusercontent.com/15038724/63730276-7e4c9400-c81f-11e9-84e1-2cd37eeb40bf.jpg)
![mode:vaporwave](https://user-images.githubusercontent.com/15038724/118332426-e8f3a680-b4be-11eb-9623-73be0128cc0a.png)
Vaporwave was created by user [@tlaskey](https://github.com/tlaskey)

**Original**
![mode:blurbobb](https://user-images.githubusercontent.com/15038724/118333046-dfb70980-b4bf-11eb-9142-97b91bbb6721.png)

![cat](https://user-images.githubusercontent.com/15038724/86549182-c20a3280-bef3-11ea-8f42-97df6b9d072f.jpg)
![mode:veneneux](https://user-images.githubusercontent.com/15038724/118332676-4ee02e00-b4bf-11eb-9a71-9974933ad014.png)

**_Moshed_** using `fatcat`.

![cat_moshed2](https://user-images.githubusercontent.com/15038724/86549187-c6365000-bef3-11ea-9906-35d2b755a8e5.jpg)

**Original**

![k_0](https://user-images.githubusercontent.com/15038724/86549099-81121e00-bef3-11ea-8302-c01af495f697.jpg)
## Datamosh in the wild

**_Moshed_** using `veneneux`.
Check out this list of awesome apps that use `datamosh`!

![k_0_moshed](https://user-images.githubusercontent.com/15038724/86549272-009fed00-bef4-11ea-9c51-bbde1a9e3802.jpg)
- [JanMichaelBot](https://github.com/tlaskey/JanMichaelBot) by user [@Tlaskey](https://github.com/tlaskey)
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./lib/mosh')
module.exports = require("./lib/mosh");
20 changes: 10 additions & 10 deletions lib/modes/blurbobb.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use strict'
"use strict";

module.exports = function (original) {
const bitmapData = original.bitmap.data
const data = Buffer.from(bitmapData)
const bitmapData = original.bitmap.data;
const data = Buffer.from(bitmapData);

let counter = 0
let counter = 0;
for (let i = 0; i < data.length; i++) {
if (counter < 64) data[i] = Math.random() * 255
if (counter < 64) data[i] = Math.random() * 255;

counter++
if (counter > 128) counter = Math.random() * 128
counter++;
if (counter > 128) counter = Math.random() * 128;
}

original.bitmap.data = data
return original
}
original.bitmap.data = data;
return original;
};
38 changes: 19 additions & 19 deletions lib/modes/fatcat.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
'use strict'
"use strict";

module.exports = function (original) {
const min = Math.min
const min = Math.min;

const bitmapData = original.bitmap.data
const data = Buffer.from(bitmapData)
const bitmapData = original.bitmap.data;
const data = Buffer.from(bitmapData);

for (let i = 0; i < data.length; i += 4) {
data[i + 0] = min(data[i + 0] * 1.4, 280)
data[i + 1] = min(data[i + 1] * 1.4, 280)
data[i + 2] = min(data[i + 2] * 1.4, 280)
data[i + 0] = min(data[i + 0] * 1.4, 280);
data[i + 1] = min(data[i + 1] * 1.4, 280);
data[i + 2] = min(data[i + 2] * 1.4, 280);
}

for (let i = 0; i < data.length; i += 4) {
data[i + 0] = min(data[i + 0] * 1.4, 280)
data[i + 1] = min(data[i + 1] * 1.4, 280)
data[i + 2] = min(data[i + 2] * 1.4, 280)
data[i + 0] = min(data[i + 0] * 1.4, 280);
data[i + 1] = min(data[i + 1] * 1.4, 280);
data[i + 2] = min(data[i + 2] * 1.4, 280);
}

for (let i = 0; i < data.length; i += 4) {
data[i + 0] = min(data[i + 0] * 1.4, 256)
data[i + 1] = min(data[i + 1] * 1.4, 256)
data[i + 2] = min(data[i + 2] * 1.4, 256)
data[i + 0] = min(data[i + 0] * 1.4, 256);
data[i + 1] = min(data[i + 1] * 1.4, 256);
data[i + 2] = min(data[i + 2] * 1.4, 256);
}

for (let i = 0; i < data.length; i += 4) {
data[i + 0] = min(data[i + 0] * 1.4, 255)
data[i + 1] = min(data[i + 1] * 1.4, 255)
data[i + 2] = min(data[i + 2] * 1.4, 255)
data[i + 0] = min(data[i + 0] * 1.4, 255);
data[i + 1] = min(data[i + 1] * 1.4, 255);
data[i + 2] = min(data[i + 2] * 1.4, 255);
}

original.bitmap.data = data
return original
}
original.bitmap.data = data;
return original;
};
32 changes: 16 additions & 16 deletions lib/modes/schifty.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
'use strict'
"use strict";

module.exports = function (original) {
const bitmapData = original.bitmap.data
let data = Buffer.from(bitmapData)
const bitmapData = original.bitmap.data;
let data = Buffer.from(bitmapData);

let size = Math.random() * 1024 * 4
let total = size
let temp = []
const storage = []
let size = Math.random() * 1024 * 4;
let total = size;
let temp = [];
const storage = [];

for (let i = 0; i < data.length; i++) {
if (i < total) temp.push(data[i])
if (i < total) temp.push(data[i]);
else {
storage.push(Buffer.from(temp))
size = Math.random() * 1024 * 2
total += size
temp = []
storage.push(Buffer.from(temp));
size = Math.random() * 1024 * 2;
total += size;
temp = [];
}
}

data = Buffer.concat(storage)
original.bitmap.data = data
data = Buffer.concat(storage);
original.bitmap.data = data;

return original
}
return original;
};
40 changes: 20 additions & 20 deletions lib/modes/vana.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
'use strict'
"use strict";

module.exports = function (original) {
const rand = Math.random
const max = Math.max
const min = Math.min
const rand = Math.random;
const max = Math.max;
const min = Math.min;

const bitmapData = original.bitmap.data
const data = Buffer.from(bitmapData)
const bitmapData = original.bitmap.data;
const data = Buffer.from(bitmapData);

function giveSeed () {
const seed = [0, 0, 0]
function giveSeed() {
const seed = [0, 0, 0];

const ind1 = Math.floor(rand() * 3)
const ind2 = Math.floor(rand() * 3)
const ind1 = Math.floor(rand() * 3);
const ind2 = Math.floor(rand() * 3);

seed[ind1] = max(rand(), 0.3)
if (rand() > 0.5) seed[ind2] = max(rand(), 0.3)
seed[ind1] = max(rand(), 0.3);
if (rand() > 0.5) seed[ind2] = max(rand(), 0.3);

return seed
return seed;
}

const seed = giveSeed()
const seed = giveSeed();

for (let i = 0; i < data.length; i += 4) {
/* RED = */
data[i + 0] = min(data[i] * seed[0] + 100 * seed[2], 255)
data[i + 0] = min(data[i] * seed[0] + 100 * seed[2], 255);
/* GREEN = */
data[i + 1] = min(data[i + 1] * seed[1] + 100 * seed[0], 255)
data[i + 1] = min(data[i + 1] * seed[1] + 100 * seed[0], 255);
/* BLUE = */
data[i + 2] = min(data[i + 2] * seed[2] + 100 * seed[1], 255)
data[i + 2] = min(data[i + 2] * seed[2] + 100 * seed[1], 255);
}

original.bitmap.data = data
return original
}
original.bitmap.data = data;
return original;
};
Loading

0 comments on commit fcd1189

Please sign in to comment.