Skip to content

Commit 6b6d85d

Browse files
committed
refactor
1 parent a201f4d commit 6b6d85d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/image-compression.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ export default async function compress (file, options) {
6464

6565
const origExceedMaxSize = tempFile.size > maxSizeByte
6666
const sizeBecomeLarger = tempFile.size > file.size
67+
// console.log('original file size', file.size)
68+
// console.log('current file size', tempFile.size)
6769

6870
// check if we need to compress or resize
6971
if (!origExceedMaxSize && !sizeBecomeLarger) {
@@ -81,6 +83,8 @@ export default async function compress (file, options) {
8183
while (remainingTrials-- && (currentSize > maxSizeByte || currentSize > sourceSize)) {
8284
const newWidth = origExceedMaxSize ? canvas.width * 0.95 : canvas.width
8385
const newHeight = origExceedMaxSize ? canvas.height * 0.95 : canvas.height;
86+
// console.log('current width', newWidth);
87+
// console.log('current height', newHeight);
8488
[newCanvas, ctx] = getNewCanvasAndCtx(newWidth, newHeight)
8589

8690
ctx.drawImage(canvas, 0, 0, newWidth, newHeight)
@@ -98,8 +102,6 @@ export default async function compress (file, options) {
98102
setProgress(Math.min(99, Math.floor((renderedSize - currentSize) / (renderedSize - maxSizeByte) * 100)))
99103
}
100104

101-
// garbage clean canvas for safari
102-
// ref: https://bugs.webkit.org/show_bug.cgi?id=195325
103105
cleanupCanvasMemory(canvas)
104106
cleanupCanvasMemory(newCanvas)
105107
cleanupCanvasMemory(maxWidthOrHeightFixedCanvas)

lib/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ export function getNewCanvasAndCtx (width, height) {
304304
* @returns null
305305
*/
306306
export function cleanupCanvasMemory (canvas) {
307+
// garbage clean canvas for safari
308+
// ref: https://bugs.webkit.org/show_bug.cgi?id=195325
307309
canvas.width = 0
308310
canvas.height = 0
309311
}

0 commit comments

Comments
 (0)