提交 4fe51580 编写于 作者: M Mugen87

ImageUtils: Create internal canvas only once

上级 1715e623
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
* @author szimek / https://github.com/szimek/ * @author szimek / https://github.com/szimek/
*/ */
var _canvas;
var ImageUtils = { var ImageUtils = {
getDataURL: function ( image ) { getDataURL: function ( image ) {
...@@ -20,11 +22,12 @@ var ImageUtils = { ...@@ -20,11 +22,12 @@ var ImageUtils = {
} else { } else {
canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ); if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
canvas.width = image.width;
canvas.height = image.height; _canvas.width = image.width;
_canvas.height = image.height;
var context = canvas.getContext( '2d' ); var context = _canvas.getContext( '2d' );
if ( image instanceof ImageData ) { if ( image instanceof ImageData ) {
...@@ -36,6 +39,8 @@ var ImageUtils = { ...@@ -36,6 +39,8 @@ var ImageUtils = {
} }
canvas = _canvas;
} }
if ( canvas.width > 2048 || canvas.height > 2048 ) { if ( canvas.width > 2048 || canvas.height > 2048 ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册