Canvas and WebGL Snapshot functions both now have optional type and encoder method settings

This commit is contained in:
Richard Davey 2018-01-07 13:27:07 +00:00
parent 37713b9f4a
commit db2e22bc76
2 changed files with 10 additions and 4 deletions

View file

@ -1,6 +1,9 @@
var CanvasSnapshot = function (canvas)
var CanvasSnapshot = function (canvas, type, encoderOptions)
{
var src = canvas.toDataURL();
if (type === undefined) { type = 'image/png'; }
if (encoderOptions === undefined) { encoderOptions = 0.92; }
var src = canvas.toDataURL(type, encoderOptions);
var image = new Image();

View file

@ -1,5 +1,8 @@
var WebGLSnapshot = function (sourceCanvas)
var WebGLSnapshot = function (sourceCanvas, type, encoderOptions)
{
if (type === undefined) { type = 'image/png'; }
if (encoderOptions === undefined) { encoderOptions = 0.92; }
var gl = sourceCanvas.getContext('experimental-webgl');
var pixels = new Uint8Array(gl.drawingBufferWidth * gl.drawingBufferHeight * 4);
gl.readPixels(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
@ -31,7 +34,7 @@ var WebGLSnapshot = function (sourceCanvas)
ctx.putImageData(imageData, 0, 0);
var src = canvas.toDataURL();
var src = canvas.toDataURL(type, encoderOptions);
var image = new Image();
image.src = src;