Skip to content

Commit 37d4274

Browse files
authored
Merge pull request #15255 from Mugen87/dev11
ImageUtils: Create internal canvas only once
2 parents c0d3ebd + 4fe5158 commit 37d4274

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/extras/ImageUtils.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* @author szimek / https://github.com/szimek/
55
*/
66

7+
var _canvas;
8+
79
var ImageUtils = {
810

911
getDataURL: function ( image ) {
@@ -20,11 +22,12 @@ var ImageUtils = {
2022

2123
} else {
2224

23-
canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
24-
canvas.width = image.width;
25-
canvas.height = image.height;
25+
if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
26+
27+
_canvas.width = image.width;
28+
_canvas.height = image.height;
2629

27-
var context = canvas.getContext( '2d' );
30+
var context = _canvas.getContext( '2d' );
2831

2932
if ( image instanceof ImageData ) {
3033

@@ -36,6 +39,8 @@ var ImageUtils = {
3639

3740
}
3841

42+
canvas = _canvas;
43+
3944
}
4045

4146
if ( canvas.width > 2048 || canvas.height > 2048 ) {

0 commit comments

Comments
 (0)