Thursday, May 2, 2013

Program To Create SVG Icon For A Software

Scalable Vector Graphics (SVG) is an XML-based vector image format. The SVG specification is developed by the World Wide Web Consortium since 1999.

Advantages of using SVG over other image formats (like JPEG and GIF) are:
  • SVG images can be created and edited with any text editor
  • SVG images can be searched, indexed, scripted, and compressed
  • 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)
  • SVG is an open standard
  • SVG files are pure XML
SVG images are zoomable, without degradation of quality, That's why most of the people use SVG images as their software icon. In this post i am going to show you, how to create SVG icon / image as shown below, for your software using C and Cairo graphics library.
NOTE: Before running the following program, plz make sure that you have already installed cairo library. (sudo apt-get install libcairo2-dev)

To Know How to create PDF files in C programming Click HERE.

 // File Name: SVGCreate.c

 #include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <cairo/cairo.h>
#include <cairo/cairo-svg.h>

void main() {
    // Declaring Variables
    cairo_t *cr;
    cairo_surface_t *surface;
    double x=25.6,  y=128.0;
    double x1=102.4, y1=230.4, x2=153.6, y2=25.6, x3=230.4, y3=128.0;
    surface = (cairo_surface_t *)cairo_svg_surface_create("R.E.N.I.svg", 250.0, 250.0);
    cr = cairo_create(surface);
    // Creating required graphics in SVG file
    cairo_move_to (cr, x, y);
    cairo_curve_to (cr, x1, y1, x2, y2, x3, y3);
    cairo_set_line_width (cr, 10.0);
    cairo_stroke (cr);
    cairo_set_source_rgba (cr, 1, 0.2, 0.2, 0.6);
    cairo_set_line_width (cr, 6.0);
    cairo_move_to (cr,x,y);   cairo_line_to (cr,x1,y1);
    cairo_move_to (cr,x2,y2); cairo_line_to (cr,x3,y3);
    cairo_stroke (cr);
    // Typing text in SVG file
    cairo_set_font_size (cr, 15);
    cairo_select_font_face (cr, "Georgia", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_source_rgb (cr, 0, 0, 0);
    cairo_move_to(cr, 140, 150);
    cairo_show_text(cr, "R.E.N.I");
    // Destroying context and surface
    cairo_destroy (cr);
    cairo_surface_destroy (surface);
}

To Run: gcc -lcairo SVGCreate.c
              ./a.out
Out Put: It will create R.E.N.I.svg file in your current directory

No comments:

Post a Comment