Dom-to-image SVG image elements - image

I'm using the brilliant dom-to-image to capture a screenshot of a d3.js dashboard and download as a png.
I've found it works better than it's competitors - the CSS transfers beautifully - but I've come across a stumbling block.
I have some SVG image elements in my dashboard:
<image x="20" y="20" width="300"height="80"
xlink:href="image/my_image.png"/>
These are either embedded directly onto the svg or as pattern definitions and they are not rendering on the PNG.
This is a know problem and one which has come up on Stack Overflow before but I haven't been able to find a solution. Any thoughts?

In order to get your svg converted to png. Just place your nodeRef in a div and inside that div let your d3.js component be written.Applying nodeRef directly over component will not work.

For me what worked was installing html-to-image and not using dom-to-image

Related

Why is Firefox displaying svg images wrong?

I encountered a weird Firefox's behaviour. It renders SVG images cutting parts of them or not displaying them at all, but only certain of images, not all of them. Chrome and IE are displaying them properly. Here is a link to the website I put said images on:
funjo.pl
Images which are not being displayed properly are logo in top menu bar and big blue logo with transparency on the big very top banner. The funny thing is that two icons a bit down on the same page (three rolls and woman's legs), which are also SVGs are being displayed properly. Could someone please tell me what's going on? I suppose there is something wrong with SVG image code itself but I can't detect what exactly.
I'm not pasting whole images' code beacuse it's too much of it. You can download these images from http://funjo.pl/media/2016/06/logo.svg and http://funjo.pl/media/2016/06/logo2.svg.
PS: If you really want me very badly to paste the whole code let me know.
PS2: I created all of SVGs on the website using Corel X7, if this information helps in anything.
PS3: I'm using the newest FF v 46.0.1.
Actually I've found a solution myself, it helped perfectly but required few more steps after exporting SVG in Corel X7 (as I mentioned in my post above there were two images, one of them with transparency). So here are the steps I made to make it being displayed properly in FF (a bit trial and error procedure but works):
I exported both SVGs again removing transparency from the one which was originally transparent, so no transparency at all in both SVG images. The one used as logo in menu bar contained all the elements grouped (logo and text were both separate but grouped), I ungrouped those elements and made them as one.
I removed height and width attributes from both SVGs.
I added preserveAspectRatio="none" attribute so I could manage width and height of the image separately, just like raster images (this CSS Tricks article helps a lot with understanting the whole resizing process).
I used SVG Optimiser tool to remove all the unnecessary bits from my images and to slim them down a little.
I downloaded optimised SVGs from above mentioned tool's website, uploaded them to my website's FTP.
I added height:(some)px and width:auto attributes in CSS
I added transparency for the one which was supposed to be transparent via CSS - opacity:0.7 in this case.
Refreshed the website and voilĂ , it works like a charm. Hope it will help someone with the similar problem as mine.
EDIT
Here are images to compare, working one and not working one.
PS: After some more trials and errors I found out that changing standard text to curves in Corel X7 makes FF render the SVG image properly without above steps, but it doesn't change the fact that it worked properly in Chrome and IE anyway even if the text wasn't changed to curves before export. Plus FF didn't display SVG exported with transparency at all and Chrome and IE did.
You could open a working and failing SVG file into your text editor and find differences in the generated HTML.
I guess there is a difference the way you save it or how the vectors and layers are put. Maybe some transparent layer on top off the image renders strange?
Applying a width of 300px or above gave me the correct results as in chrome and IE.
So just give a width as below and probably you can adjust the width as per your requirement.
Hope it helps.
<img style="width: 300px;" src="http://funjo.pl/media/2016/06/logo.svg" alt="Funjo">
I solved it by removing commas , by spaces

D3js.org banner like image gallery

I want to create an image gallery much like d3js.org has on their home page. Can someone please help? I have tried it but I am finding it difficult to link separate images to links that a in SVG element in that banner. www.d3js.org.
First, they are definitely using d3.js Hexagonal Binning.
Then, the individual elements are styled with offsets into this image: http://d3js.org/ex.jpg

SVG display difference between <img> and <object>

What's the difference between displaying a SVG image in an <img> or <object> tag? I was facing some problems using SVG images in a <img> tag on Android 3.1:
The shape in the upper example is an <img> tag and the lowest example is the exact same image but display in an <object>.
Why is this displayed a different way? And is an <object> cached like an <img>?
What do you guys suggest?
Differences when SVG is used as an image (html <img> SVG <image> or CSS background images)
no scripting
no interactivity
no external dependencies (complete in a single file)
no DOM (i.e. no script access into them from outside)
can be copied into canvas via drawImage
I suspect you're suffering from the no external dependencies rule. You may also want to check that the SVG data has a preserveAspectRatio attribute on the root element and if it does that the value of that attribute is not none.

Embedding images in SVG in React

I am using SVG inside React, but the amount of SVG tags that ReactJS allows is limited and I don't see a way to embed an <image/> SVG tag inside my JSX.
I've also tried using a fill style on a rect set to a url of an image, but it doesn't work either. Is there a workaround for this?
SVG Image is now supported in 0.14.
For prior versions, you can use dangerouslySetInnerHTML. For more about that, take a look at this issue:
https://github.com/facebook/react/issues/2069

IE9 - 11 SVG backgrounds are blurry

This is only happening in Internet explorer. I am looking for a solution. I read that ie rasterizes background images or something just like older firefox versions but what are the solutions? Im so desperate. I dont want to serve an inline img image only because of IE.
This is seriously limiting. All other browsers render the SVG 99% the same and accurately.
Use inline image SVGs. If you are concerned that the resource is download by browsers other than IE then use javascript media queries
I've found that deleting the width and height attributes of the svg root (in the svg file itself) helps a little, but not always. You will want to make sure viewBox is defined to retain the aspect ratio.

Resources