Coder Social home page Coder Social logo

petercollingridge / svg-optimiser Goto Github PK

View Code? Open in Web Editor NEW
182.0 16.0 24.0 54 KB

A python module to clear up SVG files, especially those created in Inkscape

Home Page: http://www.petercollingridge.co.uk/blog/svg-optimiser

License: Other

CSS 4.05% JavaScript 45.19% Python 40.68% HTML 10.08%
python27 svg javascript

svg-optimiser's Introduction

Python program to clean up SVG files, particularly those created by Inkscape or Illustrator

--- Current Functionality ---

Remove attributes

Remove attributes with a given name, e.g. remove 'id' attributes, which often aren't used.

Remove comments

Removes all comments.

Remove elements

Remove elements by their tag name.

Remove namespaces

Remove all attributes associated with a given namespace, e.g. remove 'sodipodi' attributes created by Inkscape.

Remove redundant groups

Move child elements outdside of group with no attributes, then delete group.

Set decimal places

Rewrite attributes to a given number of decimal places.
Strip out unnecessary trailing zeros.
  • Attributes
    • x, y, x1, y2, x2, y2
    • cx, cy
    • r, rx, ry
    • width, height
    • points
    • d

Apply transformations

Applies transformations to elements so the attribute can be removed.
  • Translation

    • In the form

      • comma: (12,34)
      • space(s): (12 34)
      • comma and space(s): (12, 34), (12 ,34), (12 , 34)
      • decimal: (1.2, 3.4)
      • negative: (-1.2, -3.4)
    • Shapes

      • line
      • rect
      • circle, ellipse
      • polyline, polygon
      • path (not fully tested)
      • g (not fully tested)
  • Scale

    • Shapes
      • path
      • rect

CSS stlying

Convert individual style attributes to CSS styling.
Remove default styles.

--- To Do ---

Remove namespaces

Remove xml namespace if possible

Groups

Remove unnecessary groups
Remove unnecessary text groups
Add groups in make styling and transforms more efficient

Transformations

  • Translation

    • In the form

      • single: (12)
    • Shapes

      • text
      • tspan
  • Rotation

    • Shapes
      • path
      • polyline/polygon
      • line
      • circle
      • rect -> polygon/path?
  • Scale

    • Shapes
      • polyline/polygon
      • line
      • circle -> ellipse?
  • SkewX and SkewY

    • Shapes
      • line
      • path
      • polyline/polygon
      • rect -> polygon/path?
      • circle -> path arc?
  • Matrix

    • Shapes
      • line
      • path
      • polyline/polygon
      • rect -> polygon/path?

CSS styling

Need to check whether style element already exists and whether class names already exist.
Ideally find most efficient way to class elements for styling.

License

svg-optimiser's People

Contributors

hooblei avatar petercollingridge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

svg-optimiser's Issues

html entities get unescaped

I just had a svg break because I had a &lt; in there and the optimizer just converted it into <. Luckily I was able to identify the problem and recover the svg, but this is a serious problem. For context, I had it in a tspan.

A solution would be adding a button to en/disable this feature or just removing it completely. I don't know your code so I can only assume things though.

http://petercollingridge.appspot.com/svg-optimiser is down

Hi Peter,

We have been using your SVG optimiser for ages and recently noticed that the site is down.

We are getting the following error:

`Error: Server Error

The server encountered an error and could not complete your request.
Please try again in 30 seconds.`

Would it be possible for you to take a look?

Thanks!

svg translate fail,miss some part of information

hi ,look follow:
<?xml version="1.0" encoding="UTF-8"?> <svg width="48px" height="48px" viewBox="0 0 48 48" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <!-- Generator: Sketch 52.2 (67145) - http://www.bohemiancoding.com/sketch --> <title>pc-dianhuae078-o</title> <desc>Created with Sketch.</desc> <g id="接单发货" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> <g id="采购单详情-修改采购单" transform="translate(-972.000000, -622.000000)" fill="#FF8200"> <g id="pc-dianhuae078-o" transform="translate(996.000000, 646.000000) scale(-1, 1) translate(-996.000000, -646.000000) translate(972.000000, 622.000000)"> <path d="M43.1526606,28.986055 C41.4341284,31.7191927 39.3069358,34.3585321 36.8397798,36.8256881 C35.1029725,38.5624954 33.2560734,40.1513394 31.3484037,41.5508257 C29.4790459,42.9166239 27.5542018,44.0897615 25.632,45.0328073 C23.7353394,45.965945 21.8082936,46.688367 19.9006239,47.1809174 C18.005945,47.668844 16.1451743,47.9178716 14.3537615,47.9178716 C10.9512661,47.9178716 7.83192661,47.0338349 5.1333578,45.2844771 C3.67706422,44.3376881 2.63889908,43.56 1.76917431,42.6546055 C0.718678899,41.5735046 0.128587156,40.5034128 0.0171743119,39.4192294 C-0.0924770642,38.2769174 0.321027523,37.1874495 1.27552294,36.2444037 C2.80469725,34.7152294 4.33255046,33.4093211 5.71794495,32.4590092 C7.71544954,31.0802202 9.31662385,30.4487339 10.6650275,30.4487339 C10.9688807,30.4487339 11.2425688,30.4817615 11.5059083,30.5401101 L11.9475963,30.6383119 L12.338422,30.8662018 C12.6407339,31.0425688 12.9932477,31.2986422 13.4397798,31.682422 C13.9677798,32.1379817 14.4675963,32.6151193 15.656367,33.7820917 C17.0047706,35.1190459 17.6490275,35.7142018 18.0761835,36.0242202 C18.3934679,36.2413211 18.7217615,36.3404037 19.1216147,36.3404037 C19.605578,36.3404037 20.1718899,36.2107156 20.8733945,35.912367 C21.6920367,35.5622752 22.629578,35.0087339 23.7271927,34.2171743 C25.315156,33.0656147 26.9960367,31.5919266 29.3398899,29.3687339 C32.1230092,26.4376514 33.8056514,24.4595229 34.9783486,22.6117431 C35.4700183,21.84 35.8322202,21.1321101 36.0594495,20.5164771 C36.2303119,20.0510092 36.3166239,19.6648073 36.3377615,19.3120734 C36.370789,18.7818716 36.2468257,18.397211 36.0385321,18.0995229 C35.7340183,17.6703853 35.1989725,17.0910826 33.8767706,15.7554495 C32.7133211,14.5807706 32.1434862,13.9864954 31.6786789,13.4461651 C31.2748624,12.9749725 30.9939083,12.5896514 30.8096147,12.2446239 L30.6435963,11.9332844 L30.5570642,11.5913394 C30.1673394,10.0522569 30.787156,8.28946789 32.1135413,6.24308257 C33.1917798,4.57717431 34.6229725,2.91082569 36.2417615,1.28366972 C37.0194495,0.505981651 37.933211,-2.30926389e-14 39.0667156,-2.30926389e-14 C40.3437798,-2.30926389e-14 41.4345688,0.623779817 42.4826422,1.59985321 C43.4558532,2.49974312 44.3059817,3.61629358 45.3027523,5.14238532 C46.6947523,7.29489908 47.5451009,9.72176147 47.8282569,12.3577982 C48.0957798,15.0143119 47.7974312,17.8342018 46.9541284,20.7351193 C46.1575046,23.4772844 44.8749358,26.2546789 43.1526606,28.986055 Z" id="Path"></path> </g> </g> </g> </svg>

this svg after the transformation,miss some part of the original information,what can I do

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.