How can I compress svg file? - html

I have a svg file with size 2.7 MB. It's too big because it's accessible on the website for a long time. So I need to compress it. I want to compress it to 200 kb. I looked for some tools online in Google, but I did not find a tool that can compress svg with a certain size
I try https://vecta.io/nano, https://www.svgminify.com/ etc. But that can't be
How can I solve this problem?
Update :
My svg file like this :
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg preserveAspectRatio="none slice" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1000" height="400" viewBox="0 102 795 400" xml:space="preserve"> <image id="image0" width="900" height="500" x="0" y="0"
xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAB4AAAAeACAYAAAAvokrGAAAABGdBTUEAALGPC/xhBQAAACBjSFJN
AAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAA
CXBIWXMAAC4jAAAuIwF4pT92AACAAElEQVR42uz92YLsuq5giwGM3Kfq1rX//wds/6FdddbMIPwg
NmCnJiKymbHG2FtrRkoUxb4BSFDNTAAAAAAAAAAAAAAAAAAA4O8n/.......AmoAAGAAARU5ErkJggg==" />
</svg>
Note :
....... a very long code
Previously I did the conversion from png to svg

Related

SVG <use> external SVG shows width / height as 0 when it's loading

I'm including an inline SVG on my webpage and inside that SVG I have a <use> to another SVG. Due to a timing bug where sometimes that use-svg has a wrong rotation what I noticed is that the <use> has width and height 0 when it's still loading the external SVG, even though I set the width and height on the <use> tag.
Having this as 0 causes problems on the rotation and subsequent processing. If I wait for it to load all is well.
(this was tested in Chrome 85.0.4183.121 and Firefox 81.0b2)
I find this strange because if I use an <image> to get my external SVG it loads the dimensions I specify when it's loading.
<use id="SvgjsUse1044" xlink:href="/images/checkmark.svg#Layer_1" width="8" height="8" x="26" y="-4"></use>
checkmark image:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="8px" height="8px" viewBox="0 0 8 8" enable-background="new 0 0 8 8" xml:space="preserve">
<path fill="#FFFFFF" d="M6.769,0.5L8,1.901L4.307,6.099L3.076,7.5L1.849,6.099L0,4l1.231-1.401l1.845,2.099L6.769,0.5z"/>
</svg>
I just want it to behave as <image> does :) I'm fully aware I can change the logic of the app to wait for it to load but it has a lot of other consequences.
Is there any way to force the browser to understand and follow the width/height of a <use> element while loading?

How to keep <image> xlink:href working after base64 encode

I am using SVG encoded as base64 to be displayed in my .html page.
I have been using basic shapes with fill, but now,
I am trying to use a SVG with a background image which is applied at the following line:
<image overflow="visible" width="650" height="882" xlink:href="<path>" transform="matrix(0.266 0 0 0.266 1.04 0)">
And below is the whole svg:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
<!ENTITY ns_extend "http://ns.adobe.com/Extensibility/1.0/">
<!ENTITY ns_ai "http://ns.adobe.com/AdobeIllustrator/10.0/">
<!ENTITY ns_graphs "http://ns.adobe.com/Graphs/1.0/">
<!ENTITY ns_vars "http://ns.adobe.com/Variables/1.0/">
<!ENTITY ns_imrep "http://ns.adobe.com/ImageReplacement/1.0/">
<!ENTITY ns_sfw "http://ns.adobe.com/SaveForWeb/1.0/">
<!ENTITY ns_custom "http://ns.adobe.com/GenericCustomNamespace/1.0/">
<!ENTITY ns_adobe_xpath "http://ns.adobe.com/XPath/1.0/">
]>
<svg version="1.1" xmlns:x="&ns_extend;" xmlns:i="&ns_ai;" xmlns:graph="&ns_graphs;"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="175px" height="199.55px"
viewBox="0 0 175 199.55" enable-background="new 0 0 175 199.55" xml:space="preserve">
<metadata>
</metadata>
<g id="Capa_2">
</g>
<g id="Capa_1">
<g>
<defs>
<path id="svg_1" d="M78.854,4.932c5.764-3.328,11.528-3.328,17.292,0l69.168,39.934c5.764,3.328,8.646,8.32,8.646,14.976v79.867
c0,6.656-2.883,11.648-8.646,14.976l-69.168,39.935c-5.764,3.327-11.528,3.327-17.292,0L9.686,154.684
c-5.764-3.327-8.646-8.319-8.646-14.976V59.841c0-6.656,2.882-11.647,8.646-14.976L78.854,4.932z"/>
</defs>
<clipPath id="svg_1_1_">
<use xlink:href="#svg_1" overflow="visible"/>
</clipPath>
<g transform="matrix(1 0 0 1 6.741370e-008 0)" clip-path="url(#svg_1_1_)">
<image overflow="visible" width="650" height="882" xlink:href="/assets/img/hexagon/1b9a4fb722.jpg" transform="matrix(0.266 0 0 0.266 1.04 0)">
</image>
</g>
</g>
</g>
</svg>
Later, already encoded to base64, css will look like this:
/* file size: 1.9ko | optimized file size: 1.7ko | base64 size: 2.2ko */
.doubleduecemenu {
background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiIFs8IUVOVElUWSBuc19leHRlbmQgImh0dHA6Ly9ucy5hZG9iZS5jb20vRXh0ZW5zaWJpbGl0eS8xLjAvIj48IUVOVElUWSBuc19haSAiaHR0cDovL25zLmFkb2JlLmNvbS9BZG9iZUlsbHVzdHJhdG9yLzEwLjAvIj48IUVOVElUWS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sOC42NDYsOC4zMiw4LjY0NiwxNC45NzZ2NzkuODY3YzAsNi42NTYtMi44ODMsMTEuNjQ4LTguNjQ2LDE0Ljk3NmwtNjkuMTY4LDM5LjkzNWMtNS43NjQsMy4zMjctMTEuNTI4LDMuMzI3LTE3LjI5MiwwTDkuNjg2LDE1NC42ODRjLTUuNzY0LTMuMzI3LTguNjQ2LTguMzE5LTguNjQ2LTE0Ljk3NlY1OS44NDFjMC02LjY1NiwyLjg4Mi0xMS42NDcsOC42NDYtMTQuOTc2TDc4Ljg1NCw0LjkzMnoiLz48L2RlZnM+PGNsaXBQYXRoIGlkPSJzdmdfMV8xXyI+PHVzZSB4bGluazpocmVmPSIjc3ZnXzEiICBvdmVyZmxvdz0idmlzaWJsZSIvPjwvY2xpcFBhdGg+PGcgdHJhbnNmb3JtPSJtYXRyaXgoMSAwIDAgMSA2Ljc0MTM3MGUtMDA4IDApIiBjbGlwLXBhdGg9InVybCgjc3ZnXzFfMV8pIj48aW1hZ2Ugb3ZlcmZsb3c9InZpc2libGUiIHdpZHRoPSI2NTAiIGhlaWdodD0iODgyIiB4bGluazpocmVmPSJodHRwOi8vZGwxLmpveGkubmV0L2RyaXZlLzIwMTYvMDYvMjUvMDAxNC8xMDkxLzk1MTM2My82My8xYjlhNGZiNzIyLmpwZyIgIHRyYW5zZm9ybT0ibWF0cml4KDAuMjY2IDAgMCAwLjI2NiAxLjA0IDApIj48L2ltYWdlPjwvZz48L2c+PC9nPjwvc3ZnPg==);
}
Problem:
Encoded base64 does not find the image that I used in the SVG.
Considerations
SVG as html works perfectly
Tried to use the image from the local server and from a hosting url
Tried to encode the path in the svg <image> to base64
I would accept any tip, and yet a solution that involves the use of svg without encoding it, however, I prefer to avoid it as far as possible.
Yet, That's how it is supposed to look like:
Thank you!
I do appreciate your time reading and thinking on this issue.
If SVG is used in an image context i.e. via an html <img> tag or as a CSS background image then it must be complete in a single file, otherwise you have a privacy leak.
If you change the image in the SVG into an internal data URL you'll find it works in Chrome and Firefox. If you imagine that the capabilities of SVG as an image are similar to raster images you won't go far wrong, after all raster images consist of a single file.
Once you've done that you can then turn the SVG file itself into the data URL just as you do now.

SVG image embedded in web page doesn't show

I'm trying to embed a set of SVG images in a blank web page.
<html><head></head>
<body>
<img width="117px" src="img/icone/phone_hex034F84.svg" alt="image">
<img width="320px" src="img/illustrazioni/SHIPPER3.svg" alt="image">
</body>
</html>
Both files are self-contained svg generated by Illustrator.
While the first does render in the browser the second (SHIPPER3.svg) doesn't.
See the code: http://104.155.112.173/land/img/illustrazioni/SHIPPER3.svg
You can download the full source from the previous link as I cannot embed it in the question (too large). Although, I'll embed here just the preamble.
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 20.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="_x5B_SHIPPER1_x5D_" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px"
y="0px" viewBox="0 0 733.3 587.8" style="enable-background:new 0 0 733.3 587.8;" xml:space="preserve">
<style type="text/css">
.st0{clip-path:url(#SVGID_2_);}
.st1{fill:#EDEDED;}
.st2{fill:#F2F2F2;}
If I copy and paste SHIPPER3.svg in http://www.freecodeformat.com/svg-editor.php it does render. I can also open it in Sketch with no problems.
I tried to embed SHIPPER3.svg also as inline svg but same, again, no show.
What I am missing?
Several problems in your SHIPPER3.svg:
all your top-level groups has class st0 which is said to be clipped out by clipPath that is outside entire viewBox
clipPath #SVGID_2_ has style="display:none;" what also hides it
See:
<svg version="1.1" viewBox="0 0 733.3 587.8">
<style type="text/css">
.st0{clip-path:url(#SVGID_2_);}
/* ... */
</style>
<defs>
<ellipse id="SVGID_1_" cx="1085.6" cy="279.3" rx="251.8" ry="233.4"/>
</defs>
<clipPath id="SVGID_2_">
<use xlink:href="#SVGID_1_" style="display:none;overflow:visible;"/>
</clipPath>
<g class="st0">
<!-- ... -->
</g>
</svg>
Further to a comment I left above, you may wish to replace the <clippath id='SVGID_2_' element with the following:
<clipPath xmlns="http://www.w3.org/2000/svg" id="SVGID_2_">
<ellipse xmlns="http://www.w3.org/2000/svg" id="SVGID_1_" cx="360" cy="290" rx="325" ry="260"/>
</clipPath>
This does 2 things. (0) it removes the link to the SVGID_1_ element by inserting the data that was inside it directly. (1) repositions and sizes the ellipse

Why is Firefox rendering my SVG so badly?

I just received an SVG file which I want to include into my HTML code.
Everything is working properly, except that Firefox somehow just renders the font int the SVG extremely bad.
Here's two screenshots:
Opera/Chrome -> perfectly fine
Firefox -> awful
I searched for about two hours now and didn't find any useful hints at all.
What could the reason be?
Thanks in advance
Edit:
Here's the XML Code from the file.
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.4, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Ebene_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="98px" height="139px" viewBox="0 0 98 139" enable-background="new 0 0 98 139" xml:space="preserve">
<image overflow="visible" width="98" height="139" xlink:href="data:image/jpeg;base64,/9j/4AA....." transform="matrix(1 0 0 1 0 0)">
</image>
</svg>

SVG Scaling Issue in IE9

Having issues using small svg in IE9. It get's chopped off on the right/is not centered:
(Supposed to be a "X")
My SVG:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.4, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 364.786 364.786" enable-background="new 0 0 364.786 364.786"
xml:space="preserve" preserveAspectRatio="xMinYMin none">
<polygon fill="#999999" points="300.988,0 182.388,118.618 63.768,0.015 0,63.745 118.639,182.376 0.015,301.018 63.745,364.786
182.395,246.127 301.045,364.771 364.786,300.988 246.15,182.371 364.771,63.742 "/>
</svg>
I removed width and height and have viewbox and preserveAspectRatio="xMinYMin none" though...
http://jsfiddle.net/dzCL2/12/
Your preserveAspectRatio value is invalid, and should be ignored by the browser:
preserveAspectRatio="xMinYMin none"
The default value of xMidYMid meet will be used when rendering in this case.
Refer to the SVG 1.1 spec for the syntax details. It's possible that IE treats the value as partially valid, applying the xMinYMin part only, that would cause a left-aligned image. Using correct syntax should hopefully fix the problem.
The correct setting which worked for me in Safari to avoiding proportional scaling:
<svg ... preserveAspectRatio="none">
</svg>