Skip to content

Commit 08b7d00

Browse files
committed
Fixed base64 method
1 parent 939fc24 commit 08b7d00

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

src/textures/TextureManager.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,26 @@ var TextureManager = new Class({
255255
}
256256
},
257257

258-
getBase64: function (key, frame)
258+
/**
259+
* Gets an existing texture frame and converts it into a base64 encoded image and returns the base64 data.
260+
*
261+
* You can also provide the image type and encoder options.
262+
*
263+
* @method Phaser.Textures.TextureManager#getBase64
264+
* @since 3.12.0
265+
*
266+
* @param {string} key - The unique string-based key of the Texture.
267+
* @param {(string|integer)} [frame] - The string-based name, or integer based index, of the Frame to get from the Texture.
268+
* @param {string} [type='image/png'] - [description]
269+
* @param {number} [encoderOptions=0.92] - [description]
270+
*
271+
* @return {string} The base64 encoded data, or an empty string if the texture frame could not be found.
272+
*/
273+
getBase64: function (key, frame, type, encoderOptions)
259274
{
275+
if (type === undefined) { type = 'image/png'; }
276+
if (encoderOptions === undefined) { encoderOptions = 0.92; }
277+
260278
var data = '';
261279

262280
var textureFrame = this.getFrame(key, frame);
@@ -280,7 +298,7 @@ var TextureManager = new Class({
280298
cd.height
281299
);
282300

283-
data = canvas.toDataURL('image/png').replace(/^data:image\/(png|jpg);base64,/, '');
301+
data = canvas.toDataURL(type, encoderOptions);
284302

285303
CanvasPool.remove(canvas);
286304
}

0 commit comments

Comments
 (0)