Thursday, December 11, 2025
HomeLanguagesPyCairo – How to get SVG file version.

PyCairo – How to get SVG file version.

In this article, we will see how we can get SVG file version in pycairo using Python.

Pycairo is a Python module providing bindings for the cairo graphics library. This library is used for creating SVG i.e vector files in python. The easiest and quickest way to open an SVG file to view it (read only) is with a modern web browser like Chrome, Firefox, Edge, or Internet Explorer—nearly all of them should provide some sort of rendering support for the SVG format.

The SVG specification was updated to version 1.1 in 2011. There are two ‘Mobile SVG Profiles,’ SVG Tiny and SVG Basic, meant for mobile devices with reduced computational and display capabilities.

In order to use the we will use get_versions with SVG surface object

Syntax : get_versions()

Argument : It takes no argument

Return : It returns list

Python




# importing pycairo
import cairo
  
# creating a SVG surface
# here geek95 is file name & 700, 700 is dimension
with cairo.SVGSurface("geek95.svg", 700, 700) as surface:
    
   # creating a cairo context object
    context = cairo.Context(surface)
  
    # creating a rectangle(square)
    context.rectangle(100, 100, 100, 100)
  
    # setting color of the context
    context.set_source_rgba(0.4, 1, 0.4, 1)
  
    # stroke out the color and width property
    context.stroke()
  
    # getting all the svg versions available
    versions = surface.get_versions()
  
  
# printing the versions
print("Value= " + str(versions))


Output:

Value= [cairo.SVGVersion.VERSION_1_1, cairo.SVGVersion.VERSION_1_2]

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32443 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6813 POSTS0 COMMENTS
Nicole Veronica
11950 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12025 POSTS0 COMMENTS
Shaida Kate Naidoo
6943 POSTS0 COMMENTS
Ted Musemwa
7196 POSTS0 COMMENTS
Thapelo Manthata
6889 POSTS0 COMMENTS
Umr Jansen
6880 POSTS0 COMMENTS