Go Back   Wiki NewForum > Career Forum (Documents/Tutorials/Advice) > Tech Forum & Tutorial > IT Forum

Reply
Views: 817 Source: CNN18.com, India-Forums, TellyChakkar, India, Times of India, Youtube, BollywoodLife, Rediff  
Thread Tools Rate Thread Display Modes
  #1  
Old 05-03-2009, 03:51 PM
welcomewiki welcomewiki is offline
Member
 
Join Date:
Dec 2008
Location:
India
Posts: 37,318
Default SVG Tutorial

SVG stands for Scalable Vector Graphics.

SVG defines graphics in XML format.

In our SVG tutorial you will learn about SVG.


SVG is a language for describing 2D-graphics and graphical applications in XML.
What you should already know

Before you continue, you should have some basic understanding of the following:
  • HTML
  • Basic XML
If you want to study these subjects first, find the tutorials on our Home page.


What is SVG?

  • SVG stands for Scalable Vector Graphics
  • SVG is used to define vector-based graphics for the Web
  • SVG defines the graphics in XML format
  • SVG graphics do NOT lose any quality if they are zoomed or resized
  • Every element and every attribute in SVG files can be animated
  • SVG is a W3C recommendation
  • SVG integrates with other W3C standards such as the DOM and XSL
SVG History & Advantages

Sun Microsystems, Adobe, Apple, IBM, and Kodak are some of the organizations that have been involved in defining SVG.
Advantages of using SVG over other image formats (like JPEG and GIF) are:
  • SVG files can be read and modified by a large range of tools (e.g. notepad)
  • SVG files are smaller and more compressible than JPEG and GIF images
  • SVG images are scalable
  • SVG images can be printed with high quality at any resolution
  • SVG images are zoomable (and the image can be zoomed without degradation)
  • Text in SVG is selectable and searchable (excellent for making maps)
  • SVG works with Java technology
  • SVG is an open standard
  • SVG files are pure XML
The main competitor to SVG is Flash.


The biggest advantage SVG has over Flash is the compliance with other standards (e.g. XSL and the DOM). Flash relies on proprietary technology that is not open source.


Look at a directory of SVG enabled software and services.
Viewing SVG Files

All browsers support SVG files nowadays, except for Internet Explorer, which needs a plug-in. Those are available for free, as for example the Adobe SVG Viewer.

Ads
Reply With Quote
  #2  
Old 05-03-2009, 03:52 PM
welcomewiki welcomewiki is offline
Member
 
Join Date:
Dec 2008
Location:
India
Posts: 37,318
Default SVG Example

SVG is written in XML.
SVG Example

The following example is an example of a simple SVG file. SVG files must be saved with an .svg extension:


"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> xmlns="http://www.w3.org/2000/svg"> stroke-width="2" fill="red"/>



(To view the SVG source, open the example and right-click in the example window. Select "View Source".)

Code explanation:

The first line contains the XML declaration. Notice the standalone attribute! This attribute specifies whether the SVG file "stands alone", or contains a reference to an external file.


standalone="no" means that the SVG document has a reference to an external file - in this case, the DTD.


The second and the third line refer to the external SVG DTD. The DTD is located at "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd". The DTD resides at the W3C and it contains all allowable SVG elements.


The SVG code begins with the element, which consists of the opening tag and the closing tag. This is the root element. The width and height attributes set the width and height of the SVG document. The version attribute defines the SVG version to be used and the xmlns attribute defines the SVG namespace.


The SVG element is used to create a circle. The cx and cy attributes define the x and y coordinates of the center of the circle. If cx and cy are omitted, the circle's center is set to (0, 0). The r attribute defines the radius of the circle.


The stroke and stroke-width attributes control how the outline of a shape appears. We set the outline of the circle to a 2px wide, black "border".
The fill attribute refers to the color inside a shape. We set the fill color to red.


The closing tag closes the root SVG element and the document.


Note: All opening tags must have closing tags!
Reply With Quote
  #3  
Old 05-03-2009, 03:53 PM
welcomewiki welcomewiki is offline
Member
 
Join Date:
Dec 2008
Location:
India
Posts: 37,318
Default SVG In HTML Pages

SVG files can be embedded into HTML documents with the tag, the tag, or the
I Wish....

It would be great if we could add SVG elements directly into the HTML code, only by referring to the SVG namespace, like this:
xmlns:svg="http://www.w3.org/2000/svg">

This is an HTML paragraph


stroke-width="2" fill="red" />

Reply With Quote
  #4  
Old 05-03-2009, 03:54 PM
welcomewiki welcomewiki is offline
Member
 
Join Date:
Dec 2008
Location:
India
Posts: 37,318
Default SVG <rect>

SVG has some predefined shape elements that can be used and manipulated by developers.
SVG Shapes

SVG has some predefined shape elements that can be used and manipulated by developers:
  • Rectangle
  • Circle
  • Ellipse
  • Line
  • Polyline
  • Polygon
  • Path
The following chapters will explain each element, starting with the rect element.


The Tag

The tag is used to create a rectangle and variations of a rectangle shape.
To understand how this works, copy the following code into Notepad and save the file as "rect1.svg". Place the file in your Web directory:



"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> xmlns="http://www.w3.org/2000/svg"> style="fill:rgb(0,0,255);stroke-width:1;
stroke:rgb(0,0,0)"/>

Code explanation:
  • The width and height attributes of the rect element define the height and the width of the rectangle
  • The style attribute is used to define CSS properties
  • The CSS fill property defines the fill color of the rectangle (either an rgb value, a color name, or a hexadecimal value)
  • The CSS stroke-width property defines the width of the border of the rectangle
  • The CSS stroke property defines the color of the border of the rectangle


Let's look at another example that contains some new attributes:



"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> xmlns="http://www.w3.org/2000/svg"> style="fill:blue;stroke:pink;stroke-width:5;
fill-opacity:0.1;stroke-opacity:0.9"/>

Code explanation:
  • The x attribute defines the left position of the rectangle (e.g. x="0" places the rectangle 0 pixels from the left of the browser window)
  • The y attribute defines the top position of the rectangle (e.g. y="0" places the rectangle 0 pixels from the top of the browser window)
  • The CSS fill-opacity property defines the opacity of the fill color (legal range: 0 to 1)
  • The CSS stroke-opacity property defines the opacity of the stroke color (legal range: 0 to 1)

Define the opacity for the whole element:



"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> xmlns="http://www.w3.org/2000/svg"> style="fill:blue;stroke:pink;stroke-width:5;
opacity:0.9"/>

Code explanation:
  • The CSS opacity property defines the opacity value for the whole element (legal range: 0 to 1)


Last example, create a rectangle with rounded corners:



"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> xmlns="http://www.w3.org/2000/svg"> height="100" style="fill:red;stroke:black;
stroke-width:5;opacity:0.5"/>

Code explanation:
  • The rx and the ry attributes rounds the corners of the rectangle
Reply With Quote
  #5  
Old 05-03-2009, 03:55 PM
welcomewiki welcomewiki is offline
Member
 
Join Date:
Dec 2008
Location:
India
Posts: 37,318
Default SVG <circle>

The tag is used to create a circle.
The Tag

The tag is used to create a circle.
Copy the following code into Notepad and save the file as "circle1.svg". Place the file in your Web directory:



"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> xmlns="http://www.w3.org/2000/svg"> stroke-width="2" fill="red"/>

Code explanation:
  • The cx and cy attributes define the x and y coordinates of the center of the circle. If cx and cy are omitted, the circle's center is set to (0, 0)
  • The r attribute defines the radius of the circle
Reply With Quote
Reply

New topics in IT Forum

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump


All times are GMT. The time now is 04:27 AM.


Powered by vBulletin® Version 3.8.10
Copyright ©2000 - 2017, vBulletin Solutions, Inc.