Skip to content

Commit 2b300bd

Browse files
author
ekletchenko
committed
Fix options object being altered by compress func
1 parent 8ab1c6a commit 2b300bd

16 files changed

+351
-212
lines changed

coverage/coverage-final.json

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

coverage/coverage-summary.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
{"total": {"lines":{"total":206,"covered":167,"skipped":0,"pct":81.07},"statements":{"total":220,"covered":169,"skipped":0,"pct":76.82},"functions":{"total":28,"covered":24,"skipped":0,"pct":85.71},"branches":{"total":103,"covered":58,"skipped":0,"pct":56.31}}
2-
,"D:\\Projects\\browser-image-compression\\lib\\image-compression.js": {"lines":{"total":47,"covered":47,"skipped":0,"pct":100},"functions":{"total":3,"covered":3,"skipped":0,"pct":100},"statements":{"total":47,"covered":47,"skipped":0,"pct":100},"branches":{"total":24,"covered":20,"skipped":0,"pct":83.33}}
3-
,"D:\\Projects\\browser-image-compression\\lib\\index.js": {"lines":{"total":30,"covered":27,"skipped":0,"pct":90},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":30,"covered":27,"skipped":0,"pct":90},"branches":{"total":19,"covered":13,"skipped":0,"pct":68.42}}
4-
,"D:\\Projects\\browser-image-compression\\lib\\utils.js": {"lines":{"total":129,"covered":93,"skipped":0,"pct":72.09},"functions":{"total":23,"covered":19,"skipped":0,"pct":82.61},"statements":{"total":143,"covered":95,"skipped":0,"pct":66.43},"branches":{"total":60,"covered":25,"skipped":0,"pct":41.67}}
1+
{"total": {"lines":{"total":213,"covered":167,"skipped":0,"pct":78.4},"statements":{"total":220,"covered":169,"skipped":0,"pct":76.82},"functions":{"total":28,"covered":24,"skipped":0,"pct":85.71},"branches":{"total":103,"covered":58,"skipped":0,"pct":56.31}}
2+
,"/home/user/WebstormProjects/browser-image-compression/lib/image-compression.js": {"lines":{"total":47,"covered":47,"skipped":0,"pct":100},"functions":{"total":3,"covered":3,"skipped":0,"pct":100},"statements":{"total":47,"covered":47,"skipped":0,"pct":100},"branches":{"total":24,"covered":20,"skipped":0,"pct":83.33}}
3+
,"/home/user/WebstormProjects/browser-image-compression/lib/index.js": {"lines":{"total":30,"covered":27,"skipped":0,"pct":90},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":30,"covered":27,"skipped":0,"pct":90},"branches":{"total":19,"covered":13,"skipped":0,"pct":68.42}}
4+
,"/home/user/WebstormProjects/browser-image-compression/lib/utils.js": {"lines":{"total":136,"covered":93,"skipped":0,"pct":68.38},"functions":{"total":23,"covered":19,"skipped":0,"pct":82.61},"statements":{"total":143,"covered":95,"skipped":0,"pct":66.43},"branches":{"total":60,"covered":25,"skipped":0,"pct":41.67}}
55
}

coverage/image-compression.js.html

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ <h1><a href="index.html">All files</a> image-compression.js</h1>
168168
<a name='L109'></a><a href='#L109'>109</a>
169169
<a name='L110'></a><a href='#L110'>110</a>
170170
<a name='L111'></a><a href='#L111'>111</a>
171-
<a name='L112'></a><a href='#L112'>112</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
171+
<a name='L112'></a><a href='#L112'>112</a>
172+
<a name='L113'></a><a href='#L113'>113</a>
173+
<a name='L114'></a><a href='#L114'>114</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
172174
<span class="cline-any cline-neutral">&nbsp;</span>
173175
<span class="cline-any cline-neutral">&nbsp;</span>
174176
<span class="cline-any cline-neutral">&nbsp;</span>
@@ -236,6 +238,8 @@ <h1><a href="index.html">All files</a> image-compression.js</h1>
236238
<span class="cline-any cline-yes">6x</span>
237239
<span class="cline-any cline-neutral">&nbsp;</span>
238240
<span class="cline-any cline-neutral">&nbsp;</span>
241+
<span class="cline-any cline-neutral">&nbsp;</span>
242+
<span class="cline-any cline-neutral">&nbsp;</span>
239243
<span class="cline-any cline-yes">6x</span>
240244
<span class="cline-any cline-neutral">&nbsp;</span>
241245
<span class="cline-any cline-yes">4x</span>
@@ -251,6 +255,8 @@ <h1><a href="index.html">All files</a> image-compression.js</h1>
251255
<span class="cline-any cline-yes">2x</span>
252256
<span class="cline-any cline-yes">9x</span>
253257
<span class="cline-any cline-yes">9x</span>
258+
<span class="cline-any cline-neutral">&nbsp;</span>
259+
<span class="cline-any cline-neutral">&nbsp;</span>
254260
<span class="cline-any cline-yes">9x</span>
255261
<span class="cline-any cline-neutral">&nbsp;</span>
256262
<span class="cline-any cline-yes">9x</span>
@@ -268,8 +274,6 @@ <h1><a href="index.html">All files</a> image-compression.js</h1>
268274
<span class="cline-any cline-yes">9x</span>
269275
<span class="cline-any cline-neutral">&nbsp;</span>
270276
<span class="cline-any cline-neutral">&nbsp;</span>
271-
<span class="cline-any cline-neutral">&nbsp;</span>
272-
<span class="cline-any cline-neutral">&nbsp;</span>
273277
<span class="cline-any cline-yes">2x</span>
274278
<span class="cline-any cline-yes">2x</span>
275279
<span class="cline-any cline-yes">2x</span>
@@ -333,9 +337,9 @@ <h1><a href="index.html">All files</a> image-compression.js</h1>
333337
incProgress()
334338
&nbsp;
335339
// exifOrientation
336-
options.exifOrientation = options.exifOrientation || <span class="branch-1 cbranch-no" title="branch not covered" >await getExifOrientation(file)</span>
340+
const exifOrientation = options.exifOrientation || <span class="branch-1 cbranch-no" title="branch not covered" >await getExifOrientation(file)</span>
337341
incProgress()
338-
const orientationFixedCanvas = (await isAutoOrientationInBrowser) ? <span class="branch-0 cbranch-no" title="branch not covered" >maxWidthOrHeightFixedCanvas </span>: followExifOrientation(maxWidthOrHeightFixedCanvas, options.exifOrientation)
342+
const orientationFixedCanvas = (await isAutoOrientationInBrowser) ? <span class="branch-0 cbranch-no" title="branch not covered" >maxWidthOrHeightFixedCanvas </span>: followExifOrientation(maxWidthOrHeightFixedCanvas, exifOrientation)
339343
incProgress()
340344
&nbsp;
341345
let quality = 1
@@ -345,6 +349,8 @@ <h1><a href="index.html">All files</a> image-compression.js</h1>
345349
&nbsp;
346350
const origExceedMaxSize = tempFile.size &gt; maxSizeByte
347351
const sizeBecomeLarger = tempFile.size &gt; file.size
352+
// console.log('original file size', file.size)
353+
// console.log('current file size', tempFile.size)
348354
&nbsp;
349355
// check if we need to compress or resize
350356
if (!origExceedMaxSize &amp;&amp; !sizeBecomeLarger) {
@@ -362,6 +368,8 @@ <h1><a href="index.html">All files</a> image-compression.js</h1>
362368
while (remainingTrials-- &amp;&amp; (currentSize &gt; maxSizeByte || currentSize &gt; sourceSize)) {
363369
const newWidth = origExceedMaxSize ? canvas.width * 0.95 : <span class="branch-1 cbranch-no" title="branch not covered" >canvas.width</span>
364370
const newHeight = origExceedMaxSize ? canvas.height * 0.95 : <span class="branch-1 cbranch-no" title="branch not covered" >canvas.height;</span>
371+
// console.log('current width', newWidth);
372+
// console.log('current height', newHeight);
365373
[newCanvas, ctx] = getNewCanvasAndCtx(newWidth, newHeight)
366374
&nbsp;
367375
ctx.drawImage(canvas, 0, 0, newWidth, newHeight)
@@ -379,8 +387,6 @@ <h1><a href="index.html">All files</a> image-compression.js</h1>
379387
setProgress(Math.min(99, Math.floor((renderedSize - currentSize) / (renderedSize - maxSizeByte) * 100)))
380388
}
381389
&nbsp;
382-
// garbage clean canvas for safari
383-
// ref: https://bugs.webkit.org/show_bug.cgi?id=195325
384390
cleanupCanvasMemory(canvas)
385391
cleanupCanvasMemory(newCanvas)
386392
cleanupCanvasMemory(maxWidthOrHeightFixedCanvas)
@@ -397,7 +403,7 @@ <h1><a href="index.html">All files</a> image-compression.js</h1>
397403
<div class='footer quiet pad2 space-top1 center small'>
398404
Code coverage generated by
399405
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
400-
at Fri May 08 2020 00:21:28 GMT+0800 (香港標準時間)
406+
at Tue Jun 16 2020 19:18:40 GMT+0300 (Moscow Standard Time)
401407
</div>
402408
</div>
403409
<script src="prettify.js"></script>

coverage/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ <h1>All files</h1>
4444

4545

4646
<div class='fl pad1y space-right2'>
47-
<span class="strong">81.07% </span>
47+
<span class="strong">78.4% </span>
4848
<span class="quiet">Lines</span>
49-
<span class='fraction'>167/206</span>
49+
<span class='fraction'>167/213</span>
5050
</div>
5151

5252

@@ -113,8 +113,8 @@ <h1>All files</h1>
113113
<td data-value="60" class="abs low">25/60</td>
114114
<td data-value="82.61" class="pct high">82.61%</td>
115115
<td data-value="23" class="abs high">19/23</td>
116-
<td data-value="72.09" class="pct medium">72.09%</td>
117-
<td data-value="129" class="abs medium">93/129</td>
116+
<td data-value="68.38" class="pct medium">68.38%</td>
117+
<td data-value="136" class="abs medium">93/136</td>
118118
</tr>
119119

120120
</tbody>
@@ -125,7 +125,7 @@ <h1>All files</h1>
125125
<div class='footer quiet pad2 space-top1 center small'>
126126
Code coverage generated by
127127
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
128-
at Fri May 08 2020 00:21:28 GMT+0800 (香港標準時間)
128+
at Tue Jun 16 2020 19:18:40 GMT+0300 (Moscow Standard Time)
129129
</div>
130130
</div>
131131
<script src="prettify.js"></script>

coverage/index.js.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ <h1><a href="index.html">All files</a> index.js</h1>
343343
<div class='footer quiet pad2 space-top1 center small'>
344344
Code coverage generated by
345345
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
346-
at Fri May 08 2020 00:21:28 GMT+0800 (香港標準時間)
346+
at Tue Jun 16 2020 19:18:40 GMT+0300 (Moscow Standard Time)
347347
</div>
348348
</div>
349349
<script src="prettify.js"></script>

coverage/lcov-report/image-compression.js.html

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ <h1><a href="index.html">All files</a> image-compression.js</h1>
168168
<a name='L109'></a><a href='#L109'>109</a>
169169
<a name='L110'></a><a href='#L110'>110</a>
170170
<a name='L111'></a><a href='#L111'>111</a>
171-
<a name='L112'></a><a href='#L112'>112</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
171+
<a name='L112'></a><a href='#L112'>112</a>
172+
<a name='L113'></a><a href='#L113'>113</a>
173+
<a name='L114'></a><a href='#L114'>114</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
172174
<span class="cline-any cline-neutral">&nbsp;</span>
173175
<span class="cline-any cline-neutral">&nbsp;</span>
174176
<span class="cline-any cline-neutral">&nbsp;</span>
@@ -236,6 +238,8 @@ <h1><a href="index.html">All files</a> image-compression.js</h1>
236238
<span class="cline-any cline-yes">6x</span>
237239
<span class="cline-any cline-neutral">&nbsp;</span>
238240
<span class="cline-any cline-neutral">&nbsp;</span>
241+
<span class="cline-any cline-neutral">&nbsp;</span>
242+
<span class="cline-any cline-neutral">&nbsp;</span>
239243
<span class="cline-any cline-yes">6x</span>
240244
<span class="cline-any cline-neutral">&nbsp;</span>
241245
<span class="cline-any cline-yes">4x</span>
@@ -251,6 +255,8 @@ <h1><a href="index.html">All files</a> image-compression.js</h1>
251255
<span class="cline-any cline-yes">2x</span>
252256
<span class="cline-any cline-yes">9x</span>
253257
<span class="cline-any cline-yes">9x</span>
258+
<span class="cline-any cline-neutral">&nbsp;</span>
259+
<span class="cline-any cline-neutral">&nbsp;</span>
254260
<span class="cline-any cline-yes">9x</span>
255261
<span class="cline-any cline-neutral">&nbsp;</span>
256262
<span class="cline-any cline-yes">9x</span>
@@ -268,8 +274,6 @@ <h1><a href="index.html">All files</a> image-compression.js</h1>
268274
<span class="cline-any cline-yes">9x</span>
269275
<span class="cline-any cline-neutral">&nbsp;</span>
270276
<span class="cline-any cline-neutral">&nbsp;</span>
271-
<span class="cline-any cline-neutral">&nbsp;</span>
272-
<span class="cline-any cline-neutral">&nbsp;</span>
273277
<span class="cline-any cline-yes">2x</span>
274278
<span class="cline-any cline-yes">2x</span>
275279
<span class="cline-any cline-yes">2x</span>
@@ -333,9 +337,9 @@ <h1><a href="index.html">All files</a> image-compression.js</h1>
333337
incProgress()
334338
&nbsp;
335339
// exifOrientation
336-
options.exifOrientation = options.exifOrientation || <span class="branch-1 cbranch-no" title="branch not covered" >await getExifOrientation(file)</span>
340+
const exifOrientation = options.exifOrientation || <span class="branch-1 cbranch-no" title="branch not covered" >await getExifOrientation(file)</span>
337341
incProgress()
338-
const orientationFixedCanvas = (await isAutoOrientationInBrowser) ? <span class="branch-0 cbranch-no" title="branch not covered" >maxWidthOrHeightFixedCanvas </span>: followExifOrientation(maxWidthOrHeightFixedCanvas, options.exifOrientation)
342+
const orientationFixedCanvas = (await isAutoOrientationInBrowser) ? <span class="branch-0 cbranch-no" title="branch not covered" >maxWidthOrHeightFixedCanvas </span>: followExifOrientation(maxWidthOrHeightFixedCanvas, exifOrientation)
339343
incProgress()
340344
&nbsp;
341345
let quality = 1
@@ -345,6 +349,8 @@ <h1><a href="index.html">All files</a> image-compression.js</h1>
345349
&nbsp;
346350
const origExceedMaxSize = tempFile.size &gt; maxSizeByte
347351
const sizeBecomeLarger = tempFile.size &gt; file.size
352+
// console.log('original file size', file.size)
353+
// console.log('current file size', tempFile.size)
348354
&nbsp;
349355
// check if we need to compress or resize
350356
if (!origExceedMaxSize &amp;&amp; !sizeBecomeLarger) {
@@ -362,6 +368,8 @@ <h1><a href="index.html">All files</a> image-compression.js</h1>
362368
while (remainingTrials-- &amp;&amp; (currentSize &gt; maxSizeByte || currentSize &gt; sourceSize)) {
363369
const newWidth = origExceedMaxSize ? canvas.width * 0.95 : <span class="branch-1 cbranch-no" title="branch not covered" >canvas.width</span>
364370
const newHeight = origExceedMaxSize ? canvas.height * 0.95 : <span class="branch-1 cbranch-no" title="branch not covered" >canvas.height;</span>
371+
// console.log('current width', newWidth);
372+
// console.log('current height', newHeight);
365373
[newCanvas, ctx] = getNewCanvasAndCtx(newWidth, newHeight)
366374
&nbsp;
367375
ctx.drawImage(canvas, 0, 0, newWidth, newHeight)
@@ -379,8 +387,6 @@ <h1><a href="index.html">All files</a> image-compression.js</h1>
379387
setProgress(Math.min(99, Math.floor((renderedSize - currentSize) / (renderedSize - maxSizeByte) * 100)))
380388
}
381389
&nbsp;
382-
// garbage clean canvas for safari
383-
// ref: https://bugs.webkit.org/show_bug.cgi?id=195325
384390
cleanupCanvasMemory(canvas)
385391
cleanupCanvasMemory(newCanvas)
386392
cleanupCanvasMemory(maxWidthOrHeightFixedCanvas)
@@ -397,7 +403,7 @@ <h1><a href="index.html">All files</a> image-compression.js</h1>
397403
<div class='footer quiet pad2 space-top1 center small'>
398404
Code coverage generated by
399405
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
400-
at Fri May 08 2020 00:21:28 GMT+0800 (香港標準時間)
406+
at Tue Jun 16 2020 19:18:40 GMT+0300 (Moscow Standard Time)
401407
</div>
402408
</div>
403409
<script src="prettify.js"></script>

coverage/lcov-report/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ <h1>All files</h1>
4444

4545

4646
<div class='fl pad1y space-right2'>
47-
<span class="strong">81.07% </span>
47+
<span class="strong">78.4% </span>
4848
<span class="quiet">Lines</span>
49-
<span class='fraction'>167/206</span>
49+
<span class='fraction'>167/213</span>
5050
</div>
5151

5252

@@ -113,8 +113,8 @@ <h1>All files</h1>
113113
<td data-value="60" class="abs low">25/60</td>
114114
<td data-value="82.61" class="pct high">82.61%</td>
115115
<td data-value="23" class="abs high">19/23</td>
116-
<td data-value="72.09" class="pct medium">72.09%</td>
117-
<td data-value="129" class="abs medium">93/129</td>
116+
<td data-value="68.38" class="pct medium">68.38%</td>
117+
<td data-value="136" class="abs medium">93/136</td>
118118
</tr>
119119

120120
</tbody>
@@ -125,7 +125,7 @@ <h1>All files</h1>
125125
<div class='footer quiet pad2 space-top1 center small'>
126126
Code coverage generated by
127127
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
128-
at Fri May 08 2020 00:21:28 GMT+0800 (香港標準時間)
128+
at Tue Jun 16 2020 19:18:40 GMT+0300 (Moscow Standard Time)
129129
</div>
130130
</div>
131131
<script src="prettify.js"></script>

coverage/lcov-report/index.js.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ <h1><a href="index.html">All files</a> index.js</h1>
343343
<div class='footer quiet pad2 space-top1 center small'>
344344
Code coverage generated by
345345
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
346-
at Fri May 08 2020 00:21:28 GMT+0800 (香港標準時間)
346+
at Tue Jun 16 2020 19:18:40 GMT+0300 (Moscow Standard Time)
347347
</div>
348348
</div>
349349
<script src="prettify.js"></script>

0 commit comments

Comments
 (0)