Introduction
With all the hype about brand-new XML formats in 2001, like the
newborn SVG, it progressively became quiet. Sure, Adobe had published
their plug-in, but the Flash plug-in was also on the rise. These days
however,a decade later, no modern Desktop browser needs a plug-in to
display SVG anymore. It’s time to use SVG in web-design.
Preparations
There are a lot of well-known programs in the design business. But
most of these products were originally made for printing purposes, even
though they were later improved to support the writing of SVG-files. In
my opinion a file of 150 to 200kbyte is no issue if you want to print
it, but it’s way too big for the web. In conclusion to that and because
of the existing idea of the semantic web, I advise to specifically consider creating an SVG for the use in web-design.
My tool of choice is Inkscape.
For using in websites the file size must not exceed 100 KB. The jump is similar, as from vinyl to compact disc in music buisness. First of all, you should answer the question, what elements are omitted.
The size of SVG files is determined mainly by the number of objects and their complexity. Through several layers, similar to the technique of glazing in oil painting creates a realistic picture. The objects themselves are described by coordinates (nodes). The typical operation of the designer with the calligraphy tool used with a drawing tablet produced significant numer of nodes. This is one cause for huge files. Some techniques are therefore not used in the production for the web. It makes sense to think about which objects, color definitions, filters can be used more then ones.
Inkscape
Inkscape is made for creating SVG. It’s the native format and it may
seem like it might not be completely ready yet. Don’t let yourself be
fooled by the version number. A number like 0.48 is the understatement
by GPL, but there are some limitations you should know and work around
that.
The Swiss knife - always a path
Inkscape mostly saves simple forms as paths, but a person can grasp the
command to create of circle better than understand the exact same shape
as a couple of points in a path. Change the markup at the end again in
the simple form. On top of that, the size of the file becomes smaller.
Use gradients and filters twice or more
An object gets properties. As an standard in Inkscape any filter or
gradient is bound to one object. The blur-filter is often used. To
change the standard behaviour open the filter dialog which contains a
powerful filter editor. You can use all of the filters on more than one
object, the process will also reduce the size of the SVG-file.The same
feature would be nice for gradients.
No clone wars
In a lot of cases you will take the same shape. Inkscape offers a way to
duplicate the shape, but it is mostly better to use the clone tool. A
clone is a use-element and will make rendering faster and the size of the file becomes even smaller, because a use is only a reference and not a couple of points.
Use name which are describing the objects
For further work with your editor, you should get a describing name for
the objects or groups. By a right click on the object, you will get a
dialog box and be able to do this.
Save the file as optimized SVG
With the version 0.48 Inkscape offers this. In this case unused
gradients or filters will be removed from the file and saved in a
compact way.
Optimized your code in a editor
Clean up the doctype
First of all, you can clean up the doctype. The rdf-declaration and
the meta-tags are not really needed. I advise to you a compact version.
Check any kind of abstraction
Find out which gradients you can use for a couple of objects. Use styles, if it’s possible.
Round floats
In my experience, such a high accuracy is not really needed. You can
reduce the size of a file enormously by rounding floats. In some cases
you can round the point from float to integer, sometimes you need 1-2
Decimal, e.g. in the matrix-Attribute. I use some needful bash-scripts
to do that and the tool 'SVG Cleaner'.
Use the title element
One of the advantages of the format is that each element can be
equipped with a title. Because of that, you can describe the content
further and maybe Google likes that, too.
Let's go - draw your own vector
Prepare a picture
Load a a fruit of your choice from a free picture website - a prefer a green apple. Increase the contrast with Gimp or something like that.
Place the picture in a background layer
At the beginning open the layer window. First place your prepared picture, rename the layer to background (or sth. like that) After being closed by clicking the lock icon and you create additional layer. Layers are grouped elements that receive a special inkscape-label. The allocation is therefore possible only if the SVG format files are stored Inkscape SVG, which is highly recommended for the first phase. When mixed mode is set to filter effects here should therefore remain normal preference.
Initially, I added a layer 'base', which contains the main body of the apple. First, i draw an ellipse, which I convert the object to a path, add nodes to and move them until they match with your picture template. The pipette can take the fill color directly from the original image.
Add layer, more objects, gradients and filter
The number of layer depends on the complexity of the drawing. I look a bit after that, what group of elements belong together.
By gradients and transparency may already have a significant spatial effect can be produced with these two objects. I let the "Fill and Stroke" dialog appears. The use of blur should be avoided at this point. So that a filter is applied. Uncertainty is needed quite often, and thus for each item would be created a new filter. Filters can affect the processing time significantly and are better added at the end. Since Safari and Internet Explorer filter anyway (still) don't understand, the graphics should be presentable without a filter.
Objects ore groups should get a identifiers
It makes sense to name the objects meaningful. Inkscape provides to a dialogue that is achieved with the right mouse button. The dialogue clearly shows that each element can have a title in Inkscape and a description of what you should also use to visually impaired users also supply a description.
Finished your work and use the Inkscape tools to reduce the filesize
As often as you can, try 'Ctrl + L' to reduce the number of nodes. Inkscape offers a clone tool, but it can't create an object without filling and without creating a stroke. But that is a prerequisite in order to give all cloned objects (use) different colors. After all the components of the portraits were created, the image can be removed with the layer 'background'.
Be carefully with filters
Now may be the use of filters. All the filters you can change with 'Edit Filter'. These filters can be assigned to the desired objects. In my opinion, ranging from 4-5 blur filter. Inkscape does already with some filters that can be used as a basis for experimentation.
Instead of this simple fruit with this technique can also be made more complex graphics.
Put it together
With the upcoming HTML5 specifiation we get a simple way the use a SVG inline in a HTML.
Personally, I prefer a way to use a switch in combination with foreign objects.
The switch-element is very powerful. If the browser understands
the path command, like all modern browsers, the foreign object will not
be displayed. Browsers, like Konqueror or old Internet Explorers display
the content within the foreign object. You can combine this with conditional comments.
That sounds great but...
Yes I know, what you are going to say. There is a workaround for the Internet Explore up to version 8, you can use a VML.
Hide Abstract