Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Commit

Permalink
Fix background style being overridden.
Browse files Browse the repository at this point in the history
  • Loading branch information
exupero committed Feb 7, 2019
1 parent 2204566 commit c378d19
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ <h3>Preview <button class="save btn">Save as PNG</button></h3>
</svg>
</li>

<li id=style-background>
<svg width="200" height="200" style="background:green">
</svg>
</li>

<li id=custom-font>
<svg width=200 height=200>
<text x=100 y=100 text-anchor=middle dy=14 style="font-family:'Stalemate';font-size:36pt;">Custom Fonts</text>
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ inlineTest('When setting xmlns on foreign object children', $('#xmlns-override')
inlineTest('When using HTML entites', $('#entities'));
inlineTest('Transformed text', $('#transformed-text'));
inlineTest('With marker-end', $('#marker-end'));
inlineTest('SVG style attribute', $('#style-background'));
inlineTest('With custom fonts', $('#custom-font'));

const $sandbox = $('#sandbox');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "save-svg-as-png",
"version": "1.4.6",
"version": "1.4.8",
"description": "Convert a browser SVG to PNG or dataUri",
"main": "lib/saveSvgAsPng.js",
"scripts": {
Expand Down
3 changes: 1 addition & 2 deletions src/saveSvgAsPng.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@

return inlineImages(el).then(() => {
let clone = el.cloneNode(true);
const {backgroundColor = 'transparent'} = options || {};
clone.style.backgroundColor = backgroundColor;
clone.style.backgroundColor = (options || {}).backgroundColor || el.style.backgroundColor;
const {width, height} = getDimensions(el, clone, w, h);

if (el.tagName !== 'svg') {
Expand Down

0 comments on commit c378d19

Please sign in to comment.