From 4fe515808f35b7e6b00d3a0fe141851d4002ace1 Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Thu, 15 Nov 2018 15:11:42 +0100 Subject: [PATCH] ImageUtils: Create internal canvas only once --- src/extras/ImageUtils.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/extras/ImageUtils.js b/src/extras/ImageUtils.js index e575c0db3c..ca1d0a4861 100644 --- a/src/extras/ImageUtils.js +++ b/src/extras/ImageUtils.js @@ -4,6 +4,8 @@ * @author szimek / https://github.com/szimek/ */ +var _canvas; + var ImageUtils = { getDataURL: function ( image ) { @@ -20,11 +22,12 @@ var ImageUtils = { } else { - canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ); - canvas.width = image.width; - canvas.height = image.height; + if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ); + + _canvas.width = image.width; + _canvas.height = image.height; - var context = canvas.getContext( '2d' ); + var context = _canvas.getContext( '2d' ); if ( image instanceof ImageData ) { @@ -36,6 +39,8 @@ var ImageUtils = { } + canvas = _canvas; + } if ( canvas.width > 2048 || canvas.height > 2048 ) { -- GitLab