This commit is contained in:
2019-01-02 19:16:16 +01:00
commit e76aafc35a
34 changed files with 13596 additions and 0 deletions

36
src/nodes/ToBlob.js Normal file
View File

@@ -0,0 +1,36 @@
import Node from './Node';
import {createCanvas} from './canvas';
export default class ToBlob extends Node {
constructor(options) {
super({
image: 'Image',
}, {
image: 'Image',
});
this.options = Object.assign({
quality: 100,
mimetype: 'image/jpeg',
}, options);
}
get mimetype() {
return this.options.mimetype;
}
get quality() {
return this.options.quality;
}
__update() {
const {width, height} = this.__in.image.value;
const canvas = createCanvas(width, height);
const ctx = canvas.getContext('2d');
ctx.putImageData(this.__in.image.value, 0, 0);
canvas.toBlob((blob) => {
this.__out.image.value = blob;
}, this.mimetype, this.quality);
}
}