git ssb

1+

punkmonk.termux / mvd



forked from ev / mvd

Tree: 3ac3f63409b2f6e177034de5ad8483d25749626a

Files: 3ac3f63409b2f6e177034de5ad8483d25749626a / dither / index.js

1163 bytesRaw
1const {pull, collect} = require('pull-stream')
2const fileReader = require('pull-file-reader')
3const drop = require('drag-and-drop-files')
4const h = require('hyperscript')
5var jimp = require('jimp')
6
7const main = h('div', 'drop an image on the screen')
8const a = h('a', {style: "display: none"})
9
10document.body.appendChild(main)
11document.body.appendChild(a)
12
13drop(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