Skip to content

Commit 343397f

Browse files
committed
cleanup
1 parent cef9b94 commit 343397f

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

formats-browser.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
module.exports = {};
2-
3-
const initializeCanvas = ({ data, width, height }) => {
1+
const initializeCanvas = ({ width, height }) => {
42
const canvas = document.createElement('canvas');
53
canvas.width = width;
64
canvas.height = height;
7-
const ctx = canvas.getContext('2d');
8-
9-
const imageData = new ImageData(data, width, height);
10-
11-
ctx.putImageData(imageData, 0, 0);
125

136
return canvas;
147
};
158

169
const convert = async ({ data, width, height }, ...blobArgs) => {
17-
const canvas = initializeCanvas({ data, width, height });
10+
const canvas = initializeCanvas({ width, height });
11+
12+
const ctx = canvas.getContext('2d');
13+
ctx.putImageData(new ImageData(data, width, height), 0, 0);
1814

1915
const blob = await new Promise((resolve, reject) => {
2016
canvas.toBlob(blob => {
@@ -31,10 +27,7 @@ const convert = async ({ data, width, height }, ...blobArgs) => {
3127
return new Uint8Array(arrayBuffer);
3228
};
3329

34-
module.exports.JPEG = async ({ data, width, height, quality }) => {
35-
return convert({ data, width, height }, 'image/jpeg', quality);
36-
};
37-
38-
module.exports.PNG = async ({ data, width, height }) => {
39-
return convert({ data, width, height }, 'image/png');
30+
module.exports = {
31+
JPEG: async ({ data, width, height, quality }) => await convert({ data, width, height }, 'image/jpeg', quality),
32+
PNG: async ({ data, width, height }) => await convert({ data, width, height }, 'image/png')
4033
};

0 commit comments

Comments
 (0)