mirror of
https://github.com/catdad-experiments/heic-convert
synced 2024-11-22 01:50:55 +00:00
cleanup
This commit is contained in:
parent
cef9b94645
commit
343397f493
@ -1,20 +1,16 @@
|
||||
module.exports = {};
|
||||
|
||||
const initializeCanvas = ({ data, width, height }) => {
|
||||
const initializeCanvas = ({ width, height }) => {
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
const imageData = new ImageData(data, width, height);
|
||||
|
||||
ctx.putImageData(imageData, 0, 0);
|
||||
|
||||
return canvas;
|
||||
};
|
||||
|
||||
const convert = async ({ data, width, height }, ...blobArgs) => {
|
||||
const canvas = initializeCanvas({ data, width, height });
|
||||
const canvas = initializeCanvas({ width, height });
|
||||
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.putImageData(new ImageData(data, width, height), 0, 0);
|
||||
|
||||
const blob = await new Promise((resolve, reject) => {
|
||||
canvas.toBlob(blob => {
|
||||
@ -31,10 +27,7 @@ const convert = async ({ data, width, height }, ...blobArgs) => {
|
||||
return new Uint8Array(arrayBuffer);
|
||||
};
|
||||
|
||||
module.exports.JPEG = async ({ data, width, height, quality }) => {
|
||||
return convert({ data, width, height }, 'image/jpeg', quality);
|
||||
};
|
||||
|
||||
module.exports.PNG = async ({ data, width, height }) => {
|
||||
return convert({ data, width, height }, 'image/png');
|
||||
module.exports = {
|
||||
JPEG: async ({ data, width, height, quality }) => await convert({ data, width, height }, 'image/jpeg', quality),
|
||||
PNG: async ({ data, width, height }) => await convert({ data, width, height }, 'image/png')
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user