Giter VIP home page Giter VIP logo

.svgdataextractor's Introduction

Simple and fast way to extract raw data (.txt) from .svg files

Programmed for extracting raw data (.txt files) from .svg files with a common pattern. This project contains sample.svg file and blank sample.txt file to make it easier for you to try it!

  • To run this yourself, review requirements.md file and do the following in terminal:
cd <path of the project on your computer>
python main.py
  • Note: requirements.txt do NOT need to be run as no libraries are required. If you do so, following error will occur...
ERROR: You must give at least one requirement to install (see "pip help install")

Table of contents

Use cases

This program helped me with extracting raw data from .svg exported Gimp paths.

Understand the output

Output is pixels' x and y coordinates in this format:

    x, y in pixels 

    1240, 1099

    2975, 2834

    ...
  • Note: The data HAVE TO begin with "C" and end with "/>" while having unwanted ' " ' at the end for this to work as intended

Understand the code

The program is written in Python 3.10

Code structure with snippets of code

  • The program opens your .svg file
def main():

    f = open("sample.svg", "r")
  • For loop that goes over every line in your .svg file and does all the magic
    for line in f.readlines():
  • l represents a line in the cycle, if its length is 0, program skips the line and move onto the next one
        l = line.split()
    
        if len(l) == 0:
            continue 
  • The data we want start with "C", only after the "C" is found, program starts storing the data to lists
        if l[0] == "C":
            i = 1
            l = l[1:]
            
        if i == 0:
            continue
  • Some unwanted elements ("/>" and '"') are present near the data we want, this removes them!
        if l[-1] == "/>":
            i = 0
            l = l[:-1]
            l[-1] = l[-1][:-1]
  • Now "uninterupted" data is further split into x and y values, those are then appended to lists
        for j in range(0, len(l)):
            x, y = l[j].split(",") 

            pixels_x.append(x)
            pixels_y.append(y)
  • The program opens .txt file as e where the extracted data will be stored and writes info about the contents of the file
    e = open("sample.txt", "w")
    e.write("# x, y in pixels")
  • x and y values are then written into the text file in the format seen above
    for j in range(0, len(pixels_x)):
        e.write("%s %s\n" % (pixels_x[j], pixels_y[j]))

.svgdataextractor's People

Contributors

scraptechguy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.