Giter VIP home page Giter VIP logo

svgclip's Introduction

svgclip

Sometimes you have an SVG file and you want to reduce its size to the actual drawing. I have had a hard time finding a good way to do this programmatically, for batch processing or other.

Googling around, one method I've found is to use Inkscape. It can be scripted like this:

inkscape --verb=FitCanvasToDrawing --verb=FileSave --verb=FileClose *.svg

That takes a long time, opens up a GUI and isn't very flexible.

However, you can also get information about the bounding box with the --query-all option to inkscape. Using this information, I wrote a python script that uses rsvg and cairo to write the drawing to a file with the right dimensions.

Since it was easy, I also added an option to add a margin to the drawing.

Make sure you have Inkscape, python-rsvg and python-cairo installed (on Ubuntu, try sudo apt-get install inkscape python-rsvg python-cairo) and then run svgclip.py inputfile -o outputfile [-m marginpixels].

Regards, Simon Kågedal Reimer

svgclip's People

Contributors

skagedal avatar

Watchers

 avatar  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.