In one of the projects, small icons in svg format were displayed near the menu, and it was necessary that when you hover the cursor over a menu item, the text and icon change color. In order not to produce a large number of pictures, it was decided to translate svg into code and use it in CSS styles.

Brief instructions on how to use SVG in CSS

We use the resulting code in our css file.

For example, take the Facebook icon ( standard icon with a slight change).

On the website https://jakearchibald.github.io/svgomg/ click "Open SVG" or simply drag the icon onto the viewing area. In the upper left corner click "CODE", highlight the code, and then click on copy icon, so we will get the code of our SVG image into the buffer.

Something like this:

Then paste the resulting code into the window above, click Converte and get the finished code background-image:

Background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20"%3e%3cpath fill-rule="evenodd" clip-rule="evenodd" fill="%23FFF" d="M12.748 16v-1h6v1h-6zm0-3h6v1h-6v-1zm4 5h -4v-1h4v1zM13.748 9.975v-3h-4v-1c0-1.104.896-2 2-2h2v-2.95h-2c-2.8.256-5 2.583-5 5.45 0 .017.005.032.005.05h-.005v.45h -3v3h3v8h3v-8h4z"/%3e%3c/svg%3e");

Copy and use it in your css.

To change the color, change fill="%23FFF" , just keep in mind that %23 is a regular # sign, that is, fill="%23000" is a regular black (#000).

Sometimes it becomes necessary to save svg as png using the browser. Unfortunately, the browser does not have a magic API that would allow this to be done without various hacks. What to do if you still want to achieve what you want?

The first idea that came to my mind was to do this through canvas, which has a method toDataURL("image/png");
So, I wrote a simple script: jsfiddle, github:

Var html = document.querySelector("svg").parentNode.innerHTML; var imgsrc = "data:image/svg+xml;base64," + btoa(html); var canvas = document.querySelector("canvas"), context = canvas.getContext("2d"); canvas.setAttribute("width", 526); canvas.setAttribute("height", 233); var image = new Image; image.src = imgsrc; image.onload = function () ( context.drawImage(image, 0, 0); var canvasdata = canvas.toDataURL("image/png"); var a = document.createElement("a"); a.textContent = " save"; a.download = "export_" + Date.now() + ".png"; a.href = canvasdata; document.body.appendChild(a); canvas.parentNode.removeChild(canvas); );

The essence of the script is simple: I converted svg to dataUri, loaded it via image, drew a picture on canvas and turned it into png. It seemed that the goal had been achieved and we could relax. This approach worked in Firefox and Chrome, but when I opened it in everyone's favorite browser, IE, I got this wonderful error:

The fact is that IE believes that the image was loaded from another host. Unfortunately, you won't be able to set origin for dataUri. Actually, a description of the rules can be found here: https://html.spec.whatwg.org/multipage/scripting.html#security-with-canvas-elements. It was possible, of course, to proxy the svg through the server, and then everything would work, but I wanted a purely client-side solution.

And then I remembered the wonderful canvg library. Using this library, I draw svg on canvas, and then proceed as in the first option: take toDataURL("image/png") . The result is this simple code: github:

Var svg = document.querySelector("svg"); var canvas = document.createElement("canvas"); canvas.height = svg.getAttribute("height"); canvas.width = svg.getAttribute("width"); canvg(canvas, svg.parentNode.innerHTML.trim()); var dataURL = canvas.toDataURL("image/png"); var data = atob(dataURL.substring("data:image/png;base64,".length)), asArray = new Uint8Array(data.length); for (var i = 0, len = data.length; i< len; ++i) { asArray[i] = data.charCodeAt(i); } var blob = new Blob(, {type: "image/png"}); saveAs(blob, "export_" + Date.now() + ".png");

It’s worth mentioning here that I also used the FileSaver library to bring up the save dialog box.
That's all, we have achieved the desired result.

One thing worth noting is that I wondered about saving svg to png when I was writing the tauCharts export plugin. Since styles in svg are set from external file To achieve maximum similarity with the original svg, I insert an inline style into the svg. And we get this result.

I hope the article will be useful to you and save your time.

The simplest way to trace a graphical object is to open or place the file in Adobe Illustrator and perform automatic tracing using the Trace Image command: Illustrator Help. Using the Image Trace Tool - CS6

*Even simpler):
Using software, the image/picture/drawing/photograph you provide is converted into a vector for 1(!) euro -> Image to vector

=== Online services ===

  • The first one is paid, although two images to start with can be created for free.

In English, although it’s not difficult to understand. There are two options for using it – online or buying a computer program. The price for online use (unlimited) is $7.95, the desktop program costs $295.00. It is possible to order manual tracing.
Of course, you can find cheaper ones on freelance portals, but the choice is up to everyone.

Accuracy

Above are some comparison images of Vector Magic, Adobe Live Trace (CS6) and Corel
Corel PowerTRACE (X6). Pay attention to the careful processing of shapes by Vector.

Ease of use

You do not need to install and know a great many options and settings to achieve an acceptable result.

You just need to answer a couple simple questions and that's all. If the result is not satisfactory, there is a “troubleshooting” manual where you can easily find the answer and solve the problem.

You can try again and again until you get a satisfactory result.

In general, you can transfer this work to Vector and do more creative tasks.

The translation is loose, but the meaning is something like this.

Source images in JPG format, GIF, PNG, BMP and TIFF. The result is in three quality options and in three formats: EPS, SVG and PNG. Upon completion, it is possible to repeat with a different desired quality and some editing.

  • Next, completely FREE .

Completely in English, but everything is clear in use. A little more settings And self made, but it's worth it.


Supported source formats:
  • PNG Portable network graphics
  • TGA Truevision Targa image
  • PBM Portable bitmap format
  • PNM Portable anymap format
  • PGM Portable graymap format
  • PPM Portable pixmap format
  • BMP Microsoft Windows bitmap image

Output formats:
  • svg Scalable Vector Graphics
  • eps Encapsulated PostScript
  • ai Adobe Illustrator
  • dxf DXF format (without splines)
  • p2e pstoedit frontend format
  • sk Sketch
  • fig XFIG 3.2
  • emf Enhanced Metafile format
  • mif Frame Maker MIF format
  • er Elastic Reality Shape file
  • epd epd format
  • pdf PDF format
  • cgm Computer Graphics Metafile
  • dr2d IFF DR2D? format
  • allows you to convert images to . You can either upload a file or provide a link to the image. It is also possible to apply digital effects.

When converting raster images (PNG or JPG) to SVG format, forms and objects will be converted to black and white vector graphics, which scales without any loss of quality. Such images can be colored using free programs on working with vector images (etc.). Photographers in most cases will not achieve the desired result when converting bitmap to SVG format.

If you are converting any vector image(for example, eps or ai format), the converter will try to preserve all vector and color data, and will also ensure that the two files are as similar as possible.

The Scalable Vector Graphics (SVG) format converter allows you to convert files of more than 130 formats. Conversion directions:

3FR to SVG, AFF to SVG, AI to SVG, ANI to SVG, ART to SVG, ARW to SVG, AVI to SVG, AVS to SVG, BMP to SVG, CDR to SVG, CGM to SVG, CIN to SVG, CMYK to SVG, CMYKA to SVG, CR2 to SVG, CRW to SVG, CUR to SVG, CUT to SVG, DCM to SVG, DCR to SVG, DCX to SVG, DDS to SVG, DFONT to SVG, DIA to SVG, DNG to SVG, DPX to SVG, DXF to SVG, EPDF to SVG, EPI to SVG, EPS to SVG, EPSF to SVG, EPSI to SVG, EPT to SVG, EPT2 to SVG, EPT3 to SVG, ERF to SVG, EXR to SVG, FAX to SVG, FIG to SVG, FITS to SVG, FPX to SVG, FRACTAL to SVG, FTS to SVG, G3 to SVG, GIF to SVG, GIF87 to SVG, GRAY to SVG, GRB to SVG, HDR to SVG, HRZ to SVG, ICB to SVG, ICO to SVG, ICON to SVG, IPL to SVG, JBG to SVG, JBIG to SVG, JNG to SVG, JP2 to SVG, JPC to SVG, JPE to SVG, JPEG to SVG, JPG to SVG, JPX to SVG, K25 to SVG, KDC to SVG, M2V to SVG, M4V to SVG, MAT to SVG, MIFF to SVG, MNG to SVG, MONO to SVG, MOV to SVG, MP4 to SVG, MPC to SVG, MPEG to SVG, MPG to SVG, MRW to SVG, MSL to SVG, MSVG to SVG, MTV to SVG, MVG to SVG, NEF to SVG, NRW to SVG, ORF to SVG, OTB to SVG, OTF to SVG, PAL to SVG, PALM to SVG, PAM to SVG, PBM to SVG, PCD to SVG, PCDS to SVG, PCL to SVG, PCT to SVG, PCX to SVG, PDB to SVG, PDF to SVG, PDFA to SVG, PEF to SVG, PES to SVG, PFA to SVG, PFB to SVG, PFM to SVG, PGM to SVG, PICON to SVG, PICT to SVG, PIX to SVG, PJPEG to SVG, PLASMA to SVG, PNG to SVG, PNG24 to SVG, PNG32 to SVG, PNG8 to SVG, PNM to SVG, PPM to SVG, PS to SVG, PSD to SVG, PTIF to SVG, PWP to SVG, RAF to SVG, RAS to SVG, RGB to SVG, RGBA to SVG, RLA to SVG, RLE to SVG, SCT to SVG, SFW to SVG, SGI to SVG, SK to SVG, SK1 to SVG, SR2 to SVG, SRF to SVG, SUN to SVG, SVG to SVG, SVGZ to SVG, TGA to SVG, TIF to SVG, TIFF to SVG, TIM to SVG, TTC to SVG, TTF to SVG, TXT to SVG, VDA to SVG, VICAR to SVG, VID to SVG, VIFF to SVG, VST to SVG, WBMP to SVG, WEBP to SVG, WMF to SVG, WMZ to SVG, WPG to SVG, X to SVG, X3F to SVG, XAML to SVG, XBM to SVG, XC to SVG, XCF to SVG, XFIG to SVG, XPM to SVG, XV to SVG, XWD to SVG, YCBCR to SVG, YCBCRA to SVG, YUV to SVG

Built on open solutions such as Autotrace, ImageMagick, and various linux graphic components.

Formats to convert:

SVG - Scalable Vector Graphics files
AI - Adobe Illustrator files (postscript based)
CGM - Computer Graphics Metafile files
WMF - Windows Metafile files
SK - Sketch/Skencil files
PDF - Portable Document Format
EPS - PostScript
PLT - HPGL for cutting plotter files

and also: P2E, FIG, EMF, MIF, ER, DXF, EPD, CGM, oDR2D

When you convert from raster images like PNG to SVG or JPG to SVG, it will convert your forms and objects in black-and-white images in vector graphics that can be enlarged without loss of quality. Then you can paint them in any vector graphics editor such as Inkscape .

Conversion of ordinary pictures, most likely, won’t have the desired result.

For best results in convert to SVG, use image with solid background.

  • To convert to SVG, select the file, wait for it to download on our server.
  • Supports almost all image formats (PNG, JPG, BMP and other). File size is not limited, but the larger the file, the more time it will take to convert.
  • After the conversion, you will see your original file and the result under it.
  • Download the result via the link.

Why do you need the SVG format and how to use it? After convert PNG to SVG or JPG to SVG

SVG (Scalable Vector Graphics) is an XML-based vector graphics format
The advantage is that you can change the image size without losing the quality and details. When you increase the size, the vector image preserves the shape of the curves, so the image can be displayed at any resolution.