Files: 3ac3f63409b2f6e177034de5ad8483d25749626a / dither / index.js
1163 bytesRaw
1 | const {pull, collect} = require('pull-stream') |
2 | const fileReader = require('pull-file-reader') |
3 | const drop = require('drag-and-drop-files') |
4 | const h = require('hyperscript') |
5 | var jimp = require('jimp') |
6 | |
7 | const main = h('div', 'drop an image on the screen') |
8 | const a = h('a', {style: "display: none"}) |
9 | |
10 | document.body.appendChild(main) |
11 | document.body.appendChild(a) |
12 | |
13 | drop(document, function (files) { |
14 | var first = files[0] |
15 | const notice = h('div', 'processing image') |
16 | |
17 | document.body.appendChild(notice) |
18 | |
19 | pull( |
20 | fileReader(first), |
21 | collect(function (err, buffs) { |
22 | var contents = Buffer.concat(buffs) |
23 | |
24 | jimp.read(contents, function (err, image) { |
25 | delete image._exif |
26 | |
27 | image.quality(30) |
28 | .scale(.25) |
29 | .dither16() |
30 | .greyscale() |
31 | .getBuffer(jimp.MIME_JPEG, function (err, buf) { |
32 | |
33 | const blob = new Blob([buf], {type: 'octet/stream'}) |
34 | const url = window.URL.createObjectURL(blob) |
35 | a.href = url |
36 | a.download = 'dithered-img.jpg' |
37 | a.click() |
38 | window.URL.revokeObjectURL(url) |
39 | document.body.removeChild(notice) |
40 | }) |
41 | }) |
42 | }) |
43 | ) |
44 | }) |
45 |
Built with git-ssb-web