Base64 / SVG HTML image not showing

I tried to use this icon

<img src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxNi4wLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB3aWR0aD0iMTI2cHgiIGhlaWdodD0iMTI2cHgiIHZpZXdCb3g9IjAgMCAxMjYgMTI2IiBlbmFibGUtYmFja2dyb3VuZD0ibmV3IDAgMCAxMjYgMTI2IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxnPg0KCTxyZWN0IHg9IjEuMDk1IiB5PSI5OC4yMjQiIHdpZHRoPSIxMjMuODEiIGhlaWdodD0iMTkuMjc1Ii8+DQoJPHJlY3QgeD0iMS4wOTUiIHk9Ijg1Ljc0IiB3aWR0aD0iMTIzLjgxIiBoZWlnaHQ9IjUuMjA1Ii8++DQo8L2c+DQo8L3N2Zz4NCg==5324e483b5f25ab4badb7c52c102103e"/> 

from this page
http://www.flaticon.com/free-icon/baggage-on-conveyor-band_48876

I just copy and paste the html code (Base64 / svg) into my website.
But the icon is not displayed. why?

Here is an example http://jsfiddle.net/Lsr4s/

UPDATE:
I do not understand. I am copying another image / icon and it is broken too, but there is no "=" jsfiddle.net/TYb59 in base64 code. Is flatIcon.com so buggy?

Can these images / icons be fixed?

+6
source share
3 answers

Encodes the base64 code you copied. Toward the end is == in the middle of the code. This is a placeholder that fits at the end of base64 code.

Remove the part after == and it will work fine.

 <img src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxNi4wLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB3aWR0aD0iMTI2cHgiIGhlaWdodD0iMTI2cHgiIHZpZXdCb3g9IjAgMCAxMjYgMTI2IiBlbmFibGUtYmFja2dyb3VuZD0ibmV3IDAgMCAxMjYgMTI2IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxnPg0KCTxyZWN0IHg9IjEuMDk1IiB5PSI5OC4yMjQiIHdpZHRoPSIxMjMuODEiIGhlaWdodD0iMTkuMjc1Ii8+DQoJPHJlY3QgeD0iMS4wOTUiIHk9Ijg1Ljc0IiB3aWR0aD0iMTIzLjgxIiBoZWlnaHQ9IjUuMjA1Ii8++DQo8L2c+DQo8L3N2Zz4NCg=="/> 

Demo: http://jsfiddle.net/Lsr4s/2/

Edit:

Downloading an svg file from the encoding of the site and base64 gives exactly the same result. If there is no signature that you can use to easily fix the code, this is what you will need to do.

I used C # code like this for base64 encoded image in a text file:

 File.WriteAllText(@"d:\temp\baggage19.txt", Convert.ToBase64String(File.ReadAllBytes(@"d:\temp\baggage19.svg"))); 
+13
source

So, after trying a few things (I really needed to display SVG as src = "data:"). I came across a couple of key points:

  • You do not need to encode it as base64, you can use pure svg, which makes it more readable, as well as shorter both in length and after gzip. It is also much easier to test / debug / edit.
  • it is unstable to have the xmlns attribute in the svg tag, whether you use base64 or utf8. It was the part that eluded me the most.

Now, without any ado, a simple example:

 <img src="data:image/svg+xml;utf8, <svg xmlns='http://www.w3.org/2000/svg'><line x1='0' y1='0' x2='200' y2='200' style='stroke:rgb(255,0,0);stroke-width:2'/></svg>" /> 

For completeness: http://jsfiddle.net/y1akw1fd/

+4
source

I would recommend downloading the image. Download it yourself and post the link. Take a look at my comment above. Not letting me post jsfiddle ..

-1
source

Source: https://habr.com/ru/post/971123/


All Articles