mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
Resizing of the SVG in the preload
One of the main qualities of SVG images, is its scalability, not being able to use this, is to reduce it to be a bit more image. An SVG file has an XML format, so it can be modified with the DOM. In order to collaborate, I have put the option to modify the parameters of the SVG and in this way make it adaptable. The modification gives the option of being able to choose the size in the preload to which you want to have the image before rasterizing it; And so avoid the subsequent scaling that will not have the same quality. You can see the example here: https://www.youtube.com/watch?v=Kd7pNjY-FLk tested in version 3.11 It does not interfere with the original code.
This commit is contained in:
parent
f46bd2cacd
commit
1816e529e1
1 changed files with 17 additions and 1 deletions
|
@ -83,7 +83,23 @@ var SVGFile = new Class({
|
|||
{
|
||||
this.state = CONST.FILE_PROCESSING;
|
||||
|
||||
var svg = [ this.xhrLoader.responseText ];
|
||||
var rText = this.xhrLoader.responseText,
|
||||
svg = [rText],
|
||||
configWidth = this.xhrSettings.width,
|
||||
configHeight = this.xhrSettings.height;
|
||||
|
||||
if (configWidth && configHeight) {
|
||||
var xD = null,
|
||||
parser = new DOMParser();
|
||||
xD = parser.parseFromString(rText, "text/xml");
|
||||
var svgXML = xD.getElementsByTagName("svg")[0];
|
||||
gA = (a) => svgXML.getAttribute(a);
|
||||
sA = (a, b) => svgXML.setAttribute(a, b);
|
||||
gA('viewBox') ? '' : sA('viewBox', '0 0 ' + gA('width') + ' ' + gA('height'));
|
||||
sA('width', configWidth);
|
||||
sA('height', configHeight);
|
||||
svg = [(new XMLSerializer()).serializeToString(svgXML)];
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue