mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 21:24:09 +00:00
Fixed base64 method
This commit is contained in:
parent
939fc24088
commit
08b7d00ce9
1 changed files with 20 additions and 2 deletions
|
@ -255,8 +255,26 @@ var TextureManager = new Class({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getBase64: function (key, frame)
|
/**
|
||||||
|
* Gets an existing texture frame and converts it into a base64 encoded image and returns the base64 data.
|
||||||
|
*
|
||||||
|
* You can also provide the image type and encoder options.
|
||||||
|
*
|
||||||
|
* @method Phaser.Textures.TextureManager#getBase64
|
||||||
|
* @since 3.12.0
|
||||||
|
*
|
||||||
|
* @param {string} key - The unique string-based key of the Texture.
|
||||||
|
* @param {(string|integer)} [frame] - The string-based name, or integer based index, of the Frame to get from the Texture.
|
||||||
|
* @param {string} [type='image/png'] - [description]
|
||||||
|
* @param {number} [encoderOptions=0.92] - [description]
|
||||||
|
*
|
||||||
|
* @return {string} The base64 encoded data, or an empty string if the texture frame could not be found.
|
||||||
|
*/
|
||||||
|
getBase64: function (key, frame, type, encoderOptions)
|
||||||
{
|
{
|
||||||
|
if (type === undefined) { type = 'image/png'; }
|
||||||
|
if (encoderOptions === undefined) { encoderOptions = 0.92; }
|
||||||
|
|
||||||
var data = '';
|
var data = '';
|
||||||
|
|
||||||
var textureFrame = this.getFrame(key, frame);
|
var textureFrame = this.getFrame(key, frame);
|
||||||
|
@ -280,7 +298,7 @@ var TextureManager = new Class({
|
||||||
cd.height
|
cd.height
|
||||||
);
|
);
|
||||||
|
|
||||||
data = canvas.toDataURL('image/png').replace(/^data:image\/(png|jpg);base64,/, '');
|
data = canvas.toDataURL(type, encoderOptions);
|
||||||
|
|
||||||
CanvasPool.remove(canvas);
|
CanvasPool.remove(canvas);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue