api node - compression output ability
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import Node from './Node';
|
import Node from './Node';
|
||||||
import {ImageVar, NumberVar, StringVar} from './io/AbstractIOSet';
|
import {BooleanVar, ImageVar, NumberVar, StringVar} from './io/AbstractIOSet';
|
||||||
import throttle from 'lodash/throttle'
|
import throttle from 'lodash/throttle'
|
||||||
import {createCanvas, mediaSize, paintToCanvas} from './canvas';
|
import {createCanvas, mediaSize, paintToCanvas} from './canvas';
|
||||||
|
|
||||||
@@ -64,6 +64,16 @@ const inputs = {
|
|||||||
type: 'Number',
|
type: 'Number',
|
||||||
default: 10000,
|
default: 10000,
|
||||||
} as NumberVar,
|
} as NumberVar,
|
||||||
|
compress: {
|
||||||
|
type: 'Boolean',
|
||||||
|
default: false,
|
||||||
|
} as BooleanVar,
|
||||||
|
quality: {
|
||||||
|
type: 'Number',
|
||||||
|
default: 95,
|
||||||
|
min: 0,
|
||||||
|
max: 100,
|
||||||
|
} as NumberVar,
|
||||||
};
|
};
|
||||||
|
|
||||||
const outputs = {
|
const outputs = {
|
||||||
@@ -182,12 +192,16 @@ export default class Api extends Node<typeof inputs, typeof outputs> {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return await new Promise((resolve, reject) => {
|
return await new Promise((resolve, reject) => {
|
||||||
this.tempCanvas.toBlob((blob) => {
|
this.tempCanvas.toBlob(
|
||||||
|
(blob) => {
|
||||||
if (!blob) {
|
if (!blob) {
|
||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
resolve(blob);
|
resolve(blob);
|
||||||
})
|
},
|
||||||
|
this.in.compress.value ? 'image/jpeg' : 'image/png',
|
||||||
|
this.in.compress.value,
|
||||||
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user