I am trying to show base64 encoded SVG image in an image tag .
<img width="150" height="150" class="thumbnail-image" src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTM2NiIgaGVpZ2h0PSI3NjgiIGNsYXNzPSJvdmVybGF5IG1haW4tdHJlZS1zdmctYm94IiBjcm9zc29yaWdpbj0iYW5vbnltb3VzIiBpZD0ic3ZnIiB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgaWQ9InN2Z0dyb3VwIiB0cmFuc2Zvcm09InRyYW5zbGF0ZSg2ODMsMjg0KSI+PHBhdGggY2xhc3M9Imxpbmsgc2luZ2xlUGFyZW50IGlwLWFuaW1hdGlvbiIgc3Ryb2tlLXdpZHRoPSIxLjVweCIgc3Ryb2tlPSIjMDNBOUY0IiBmaWxsPSJub25lIiBkPSJNLTI2LDRDLTE0Nyw0IC0xNDcsMjAgLTI2OCwyMCIgbWFya2VyLXN0YXJ0PSJ1cmwoI2Fycm93aGVhZFJhZGlhbFN0YXJ0LXJvb3QtZW0tc2VydmVyLTEpIiBtYXJrZXItZW5kPSJ1cmwoI2Fycm93aGVhZFJhZGlhbEVuZC1yb290LWVtLXNlcnZlci0xKSIgdGFyZ2V0aWQ9InNlcnZlci0xIiBzb3VyY2VpZD0icm9vdC1lbSIgc3R5bGU9InN0cm9rZS1kYXNoYXJyYXk6IDQ7IGFuaW1hdGlvbi1kaXJlY3Rpb246IHJldmVyc2U7Ii8+PHBhdGggY2xhc3M9Imxpbmsgc2luZ2xlUGFyZW50IGlwLWFuaW1hdGlvbiIgc3Ryb2tlLXdpZHRoPSIxLjVweCIgc3Ryb2tlPSIjMDNBOUY0IiBmaWxsPSJub25lIiBkPSJNLTI2OCwyMEMtMTQ3LDIwIC0xNDcsMTk2IC0yNS45OTk5OTk5OTk5OTk5OSwxOTYiIG1hcmtlci1zdGFydD0idXJsKCNhcnJvd2hlYWRSYWRpYWxTdGFydC1zZXJ2ZXItMS1jbG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bmQtc2VydmVyLTEtY2xpZW50LTEyNiIgdmlld0JveD0iMCAtNSAxMCAxMCIgcmVmWD0iMCIgcmVmWT0iMCIgbWFya2VyV2lkdGg9IjYiIG1hcmtlckhlaWdodD0iNiIgb3JpZW50PSJhdXRvIiBmaWxsPSIjMDNBOUY0Ij48cGF0aCBkPSJNMCwtNUwxMCwwTDAsNSIvPjwvbWFya2VyPjwvZGVmcz48ZGVmcz48bWFya2VyIGlkPSJhcnJvd2hlYWRSYWRpYWxTdGFydC1yb290LWVtLXNlcnZlci0xIiB2aWV3Qm94PSIwIC01IDEwIDEwIiByZWZYPSIwIiByZWZZPSIwIiBtYXJrZXJXaWR0aD0iNiIgbWFya2VySGVpZ2h0PSI2IiBvcmllbnQ9ImF1dG8iIGZpbGw9IiMwM0E5RjQiPjxwYXRoIGQ9Ik0wLDBMMTAsLTVMMTAsNVoiLz48L21hcmtlcj48bWFya2VyIGlkPSJhcnJvd2hlYWRSYWRpYWxTdGFydC1zZXJ2ZXItMS1jbGllbnQtMTI2IiB2aWV3Qm94PSIwIC01IDEwIDEwIiByZWZYPSIwIiByZWZZPSIwIiBtYXJrZXJXaWR0aD0iNiIgbWFya2VySGVpZ2h0PSI2IiBvcmllbnQ9ImF1dG8iIGZpbGw9IiMwM0E5RjQiPjxwYXRoIGQ9Ik0wLDBMMTAsLTVMMTAsNVoiLz48L21hcmtlcj48L2RlZnM+PC9zdmc+">
jsFiddle Link
My image tag size is fixed and small (150*150) where as my svg size can vary(currently 1366*768).
In all other browsers svg image is scaled to image tag dimensions.
In IE image itself is not showing up.
If I increase image tag dimensions say 1000*1000 it is showing.
What I should be doing to show the image in IE like in other bowsers?
You should add viewBox="0 0 [width] [height]" to the <svg /> root element to make it scale.
Here's your fiddle with viewBox="0 0 1366 768":
https://jsfiddle.net/xdcqagL4/1/
BTW you can also look into the preserveAspectRatio attribute which allows you control how the image is scaled.
Here's a great write-up on the SVG coordinate system: https://sarasoueidan.com/blog/svg-coordinate-systems/
Related
I'm working with animated SVGs / Snap.svg for the first time, so please forgive my lack of knowledge on this subject.
I made a series of 3 animated SVG "frames" (400x300px), each nested within a larger SVG (1200x300px) to contain them all. A div element with a clip style property hides the other two "frames" when they're not ready to be shown.
Using Snap.svg, each frame is supposed to "slide" into view using translate after a certain amount of time, and within each frame are some animated elements.
Long story short: the animation looks perfect in Firefox, but it looks awful in Chrome/Webkit. In Chrome, it looks like each of the frames are just being stacked on top of each other instead of side-by-side.
In addition, two of the elements (the cow circle joules and the graph circle graph) are rendering in the upper-left corner instead of using their translate property to position them in the center-right area.
You can see the animation in Plunker. Please try it out in both browsers to see what I mean.
http://plnkr.co/UhTy83
Firefox GIF screen capture:
Chrome GIF screen capture:
Thanks Ian in the comments to my question! Swapping out the <svg> tags for <g> (group) tags fixed this problem. It's interesting to me that Firefox allows you to transform <svg> elements but Webkit does not.
Before:
<svg class="slides" width="1200" height="300">
<svg class="slide1" width="400" height="300"></svg>
<svg class="slide2" width="400" height="300"></svg>
<svg class="slide3" width="400" height="300"></svg>
</svg>
After:
<svg class="slides" width="1200" height="300">
<g class="slide1"></g>
<g class="slide2"></g>
<g class="slide3"></g>
</svg>
In order to transform SVG to PNG, I put svg innerHTML content in an img tag like this :
<img src="data:image/svg+xml;UTF8,<svg> ....</svg>"> />
SVG picture is not correctly displayed especially the pictures inside SVG tag like this (others svg tag are correctly displayed) :
<image xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="none" xlink:href="../../Content/Images/picture.png" height="38" width="38" y="17" x="17"/>
Are browsers support this case ?
Thanks for your help
For privacy reasons if an SVG file is being used in an image context i.e. via an html <img> tag or as a background CSS image it must be complete in a single file.
This means that any images in the SVG file must be encoded as data URIs.
I am getting svg data by api call and appending it to div in a DOM. There are 13-14 svg elements I am getting and appending it to a single div. I want to display all this svgs in a row. If I give width: 5.5%; to svg elements, all the svgs display in a row. But when I resize window or monitor size is small, all svgs overlap each other. I've created an example in jsfiddle. Please find this fiddle
I tried with preserveAspectRatio and viewBox in svg but it's not working.
Update: I've updated fiddle. In a default size of resule in jsfiddle, overlapping is visible. I want it to be responsive.
How do I make these svgs responsive so that it doesn't overlap each other?
For these purpose better to use img tag:
<img src="path_to_svg" style="width: 5.5%" />
And in the svg file you should add attribute such as
<svg width="100%" height="100%"> .... </svg>
In this case image will resize as you want.
I got some moveable items in a svg-element as shown here:
JSfiddle: http://jsfiddle.net/xfvf4/37/
<svg xmlns="http://www.w3.org/2000/svg" height="300" width="300" version="1.1"></div>
As you can see, the items can be moved to the edge of the svg. I tried to achieve that the svg gets bigger as moving an element to the edge. i.e. if you move a rechtangle to an area near an edge (i.e. 20px), the svg gets bigger as you are moving the item.
Given an SVG like the one from this Google Visualization Example, there are circles drawn on the svg like this:
<circle cx="448.0843694002127" cy="236.6677163333033" r="12" stroke="#cccccc" stroke-width="1" fill="#0000ff"/>
I tried using firebug to manually replace that with a sample image at the same x/y coordinates, so for instance replacing the above code with:
<img width="50px" height="50px" cy="135.71439117815066" cx="343.43783232923863" xlink:href="http://upload.wikimedia.org/wikipedia/commons/thumb/1/1e/Flag_of_Fukuyama%2C_Hiroshima.png/320px-Flag_of_Fukuyama%2C_Hiroshima.png">
But that doesn't work (nothing seems to render properly). I thought perhaps using cx/cy was the issue, so I tried switching those to just regular x/y properties:
<img width="50px" height="50px" xlink:href="http://upload.wikimedia.org/wikipedia/commons/thumb/1/1e/Flag_of_Fukuyama%2C_Hiroshima.png/320px-Flag_of_Fukuyama%2C_Hiroshima.png" x="343.43783232923863" y="135.71439117815066">
Again, no-go.
I tried the technique used here:
Does SVG support embedding of bitmap images?
But again, it didn't render the image in the SVG.
I checked all over Stack Overflow, but found information only on how to tile a circle with an image:
Add a background image (.png) to a SVG circle shape
This has its own set of images as the pattern just tiles and can't be resized for each shape.
Is there any reliable way of doing this? Ideally, I want to loop through each circle and replace it with an image that will be sized to the circle it replaces.
I downloaded the SVG and added the image manually, but I get the following error:
XML Parsing Error: prefix not bound to a namespace
Location: (removed
for privacy)
Line Number 2, Column 1:<image width="50px"
height="50px" y="135.71439117815066" x="343.43783232923863"
xlink:href="http://upload.wikimedia.org/wikipedia/commons/thumb/1/1e/Flag_of_Fukuyama%2C_Hiroshima.png/320px-Flag_of_Fukuyama%2C_Hiroshima.png">
^
The element you want is <image> not <img>.
And the attributes cx and cy are meaningless on <image> elements. You can use x and y instead (like in your second attempt), and note that you are required to specify a non-zero width and height on the <image> element (again like in your second attempt). See the svg spec for the details.
Just create a mask using an image. The draw the circle or any other graphics referencing the mask.