Coder Social home page Coder Social logo

razrfalcon / svgcleaner Goto Github PK

View Code? Open in Web Editor NEW
1.6K 35.0 94.0 3.99 MB

svgcleaner could help you to clean up your SVG files from the unnecessary data.

License: GNU General Public License v2.0

Rust 98.20% QMake 0.04% C++ 0.97% JavaScript 0.79%
svg cleaner rust

svgcleaner's Introduction

SWUbanner

vshymanskyy's GitHub stats

svgcleaner's People

Contributors

a1346054 avatar aaronfranke avatar evuez avatar freelance-tech-writer avatar hexcube avatar johncoates avatar jokalliauer avatar lencioni avatar nthykier avatar razrfalcon avatar yisibl 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

svgcleaner's Issues

Detect equal subpaths and replace them with 'use'

<path d="m 10 20 l 30 40 l 50 60 m 10 20 l 30 40 l 50 60 m 10 20 l 30 40 l 50 60"/>

into

<path id="p" d="m 10 20 l 30 40 l 50 60"/>
<use xlink:href="#p"/>
<use xlink:href="#p"/>

The problem is in detecting this subpaths and estimating that it's actually shorter.

Add separate option to remove title element

Right now the title element is included in the option "Remove invisible elements" which also handles desc, script and others.

Depending on the context, the title element is not exactly invisible, as it is for example used in browsers (Firefox, Chrome/Safari/Opera) to display a tooltip.

For me it would be very useful to

  • exclude title element from "Remove invisible elements"
  • add separate option "Remove title element" which does as it says when checked

btw, thanks for this useful piece of software. :)

Resolve 'use'

If a use is linked to the element in the defs and this element is used only by this use we can replace use with this element.

The trick is in resolving attributes inheritance.

Join sequential paths

<path d="m 50 50 l 10 10"/>
<path d="m 30 30 l 60 60"/>

into

<path d="m 50 50 l 10 10 m 30 30 l 60 60"/>

Main problem is in detecting that all attributes is equal.

(Suggestion) Add functionality to remove unneeded transformation attributes

Suggestion: add a functionality that removes unneeded transform attributes (which Inkscape continually adds), to further compress files.

Example:
<use id=use5620 transform=translate(2772.5505,2000.6447) height=570 width=1000 x=1435.58 y=93.66 xlink:href=#foobar />
to
<use id=use5620 x=4208.1305 y=2094.3047 xlink:href=#foobar>

(The height and width attributes would ideally also be removed in the compression process, as the element is <use> and will look the same regardless of what height and width are.)

matrix values and white spacing

Using SVGCleaner the following line:
transform="matrix(-1,0,0,1,552.55,-389.63)"
is shortened to:
transform="matrix(-1 0 0 1 552.55-389.63)"

The missing space before -389.63 confuses FireFox 27.0.1 and the svg is not displayed. Chrome and IE seem to be doing fine. If you believe the problem is with FF I will forward the report.

You can find the .svg causing the issue at:
http://pastebin.com/bz5AmLuz

Remove elements covered by other elements

The problem is that we have to represent all shapes via Bézier curves, aka paths. Apply transforms to them. And detect that they are covered, using unknown for now, formula.

Also we have to account: opacity, filters, fill, stroke, clip-path, mask, marker, etc...

Minify SVG

Just stumbled across this project and I like the idea!

I am starting to only provide SVG graphics for websites I design (because why not!) and excess spaces, tabs and newlines etc. are extra bytes to transfer. Do you plan to provide a "minify" feature similar to what exists for JS and CSS?

I apologise if it's already implemented. I haven't looked at the source just yet.

numbers without separators

When svgcleaner re-computes coordinates and writes them back it does not place white-spaces or seperators like comma. For example in various cases I got following result after svgcleaner-cli "cleaned" SVGs created with InkScape:
<path id="polygon5" d="... -3.498l35.916 ..."/>

The problem is that these two values could be mis-interpreted. That would increase robustness. In my case I used librsvg with cairo-backend. The resulting image had infinite long lines.

Better would be to write
-3.498l35 0.916
or
-3.498l35 .916

Now I got correct results.

Multiple text coordinates being removed incorrectly.

It is common in charts to specify the axis labels in one text or tspan element with multiple coordinates to spread the characters across the axis. eg.

<text x="0 10 20 30 40" y="0">01234</text>

SVGCleaner is removing the extra coordinates like so:

<text x="0" y="0">01234</text>

this has the undesirable effect of scrunching the labels together.
It is permissible for both coordinates to be multiple.

While I am here I'd like to add my voice to those who said that squeezing every last byte out is not the only reason to use SVGCleaner. I want SVG I can edit by hand. These goals are not contradictory, well crafted SVG will almost always be smaller than machine generated.

Rounding of dy-attribute in em-units fails

When I use Visio 2007 to export a drawing to SVG, some of the text (tspan) elements have dy-attributes specified in em-units. These values are rounded to "0" (when --skip-rounding-numbers is not used).

With --skip-rounding-numbers (correct):
<tspan x="4.11" dy="1.2em" font-size="1em">text</tspan>

Without --skip-rounding-numbers:
<tspan x="4.11" dy="0" font-size="1em">text</tspan>

svgcleaner -cli terminates in "unusual way"

Hi!

Running svg cleaner in cli through ANT build and when sag cleaner runs into problems it terminates in "an unusual way" according to ANT.

The problem is that SVG Cleaner gets into trouble converting height to px. I'm working around this issue since the problematic value of height is due to a failure in a previous transformation of the svg.

This is just to inform about that this issue might arise when there is an error in converting with svg cleaner as cli.

[echo] Clean pixelized/101757.svg
[exec] The initial file size is: 1308308
[exec] The initial number of elements is: 2779
[exec] The initial number of attributes is: 9630
[exec] Error: could not convert height to px
[exec]
[exec] This application has requested the Runtime to terminate it in an unusual way.
[exec] Please contact the application's support team for more information.
[exec] Result: 3
´´´

svgcleaner output is crashed

From version 0.5 (tested 0.5.1 and 0.5.2), svgcleaner fails to process files when a custom option is selected.

For example, keep existing paths data or inside transform attributes, inside coordinate attrributes, inside other attributes (set to 1).

Steps to reproduce :

  1. install version 0.5.2 on Mac OS Lion (same problem on W7 same version)
  2. select an input folder with test SVG (attached) and empty output folder
  3. running with default option works fine. That proves the input SVG are OK.
  4. select a custom option
  5. run

For steps 2 to 5, see screenshots.

step 2 :
step 2

step 3 :
step 3

step 4 :

step 4

step 5 :

step 5

Join LineTo segments

Join LineTo segments which are lying on the same line:

M 10 10 L 50 50 L 100 100 -> M 10 10 L 100 100

unable to reduce the precision of absolute paths

I noticed that even using --attributes-prec=1, the attributes and coordinates of absolute paths are not changed :

./svgcleaner-cli /Users/aadant/Downloads/input/test.svg /Users/aadant/Downloads/test_svgcleaner/out/out.svg --transfs-prec=1 --coords-prec=1 --keep-absolute-paths --attributes-prec=1 --keep-unused-symbols --keep-unref-ids

(for test files, see issue 6)

then check the path precision is still the same while version 0.4 processed them.

Build error under Arch Linux 64 bit, git head

This is what I get:

Compiling svgcleaner v0.6.92 (file:///home/haawda/paketierung/meine_Pakete/svgcleaner-git/src/SVGCleaner)
Running rustc src/lib.rs --crate-name svgcleaner --crate-type lib -C opt-level=3 --out-dir /home/haawda/paketierung/meine_Pakete/svgcleaner-git/src/SVGCleaner/target/release --emit=dep-info,link -L dependency=/home/haawda/paketierung/meine_Pakete/svgcleaner-git/src/SVGCleaner/target/release -L dependency=/home/haawda/paketierung/meine_Pakete/svgcleaner-git/src/SVGCleaner/target/release/deps --extern svgdom=/home/haawda/paketierung/meine_Pakete/svgcleaner-git/src/SVGCleaner/target/release/deps/libsvgdom-a1497506a80f39da.rlib --extern clap=/home/haawda/paketierung/meine_Pakete/svgcleaner-git/src/SVGCleaner/target/release/deps/libclap-315a0a334d3f6b4c.rlib
error: file not found for module rm_invalid_stops
--> src/task/mod.rs:64:5
|
64 | mod rm_invalid_stops;
| ^^^^^^^^^^^^^^^^
|
= help: name the file either rm_invalid_stops.rs or rm_invalid_stops/mod.rs inside the directory "src/task"

error: aborting due to previous error

error: Could not compile svgcleaner.

Caused by:
Process didn't exit successfully: rustc src/lib.rs --crate-name svgcleaner --crate-type lib -C opt-level=3 --out-dir /home/haawda/paketierung/meine_Pakete/svgcleaner-git/src/SVGCleaner/target/release --emit=dep-info,link -L dependency=/home/haawda/paketierung/meine_Pakete/svgcleaner-git/src/SVGCleaner/target/release -L dependency=/home/haawda/paketierung/meine_Pakete/svgcleaner-git/src/SVGCleaner/target/release/deps --extern svgdom=/home/haawda/paketierung/meine_Pakete/svgcleaner-git/src/SVGCleaner/target/release/deps/libsvgdom-a1497506a80f39da.rlib --extern clap=/home/haawda/paketierung/meine_Pakete/svgcleaner-git/src/SVGCleaner/target/release/deps/libclap-315a0a334d3f6b4c.rlib (exit code: 101)

The GUI fails to pass the correct input directory for the cli on Windows

I just tried v0.6.1 GUI wizard on Windows 7 x64, with a directory in the files list. When starting the process I get a number of the cli crash messages.

The command line for the launched svgcleaner-cli.exe is following: C:\svg-cleaner\svgcleaner-cli C:/Users/ljani/Desktop/svg-input/C:/Users/ljani/svg-input/1.svg C:/Users/ljani/svg-output//1.svg --preset=complete --short-output. Take a look at the input path, it seems that the path is actually inserted twice and thus crashing the cli. I tried using the cli manually and it works beautifully.

Thanks for the awesome software!

EDIT: specifying the images one-by-one, there's no such a problem, only when you specify a directory input.

Use of SVGCleaner in CLI

I am unable to find a documentation explaining how to use this wonderful software in CLI, any help would be appreciated.

Install guide

The install file it's not compete because not explain the folder to use for launch the command.

Needs to remove font & text properties

When creating SVG files with inkscape that involves text, I often convert the text to paths. However inkscape still saves the relevant SVG tags with font and text information even though there is no text. SVG cleaner does not seem to be removing those font and text properties.

]> being converted to ]&gt;

So when running an SVG file through the cleaner, it always breaks the file by replacing the trailing '>' with '>'. I've tried unchecking every option and it still occurs. This is the bit of code at the top of the file it's affecting.

I don't know if this is a bug or I'm missing something I can do to keep it from replacing that. Any help would be appreciated. Thanks

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
    <!ENTITY ns_extend "http://ns.adobe.com/Extensibility/1.0/">
    <!ENTITY ns_ai "http://ns.adobe.com/AdobeIllustrator/10.0/">
    <!ENTITY ns_graphs "http://ns.adobe.com/Graphs/1.0/">
    <!ENTITY ns_vars "http://ns.adobe.com/Variables/1.0/">
    <!ENTITY ns_imrep "http://ns.adobe.com/ImageReplacement/1.0/">
    <!ENTITY ns_sfw "http://ns.adobe.com/SaveForWeb/1.0/">
    <!ENTITY ns_custom "http://ns.adobe.com/GenericCustomNamespace/1.0/">
    <!ENTITY ns_adobe_xpath "http://ns.adobe.com/XPath/1.0/">
]>

Regroup elements by styles

Collect ranges of sequential elements with the same attribute and move this elements to group.

<rect fill="red"/>
<rect fill="red"/>
<rect fill="red"/>
<rect fill="red" stroke="blue"/>
<rect stroke="blue"/>
<rect stroke="blue"/>
<rect stroke="blue"/>
<rect stroke="blue"/>

into

<g fill="red">
  <rect/>
  <rect/>
  <rect/>
</g>
<g stroke="blue">
  <rect fill="red"/>
  <rect/>
  <rect/>
  <rect/>
  <rect/>
</g>

The trick in detecting optimal ranges.

indent with tabs

Hi RazrFalcon,
would you consider to add the possibility to use tab chars instead of spaces for indenting?

Doesn't compile

tried trunk and v0.6.2 on Gentoo, GCC 4.9.2. Qt 4.8.6. Fails in both cases with

wizarddialog.cpp: In member function ‘void WizardDialog::onRadioSelected()’:
wizarddialog.cpp:299:59: error: ‘class QRadioButton’ has no member named ‘accessibleName’
     settings.setValue(SettingKey::Wizard::SaveMode, rBtn->accessibleName());
                                                           ^
wizarddialog.cpp: In member function ‘QString WizardDialog::findLabel(const QString&)’:
wizarddialog.cpp:549:22: error: ‘class QLabel’ has no member named ‘accessibleName’
             if (lbl->accessibleName() == accessibleName)
                      ^

OS X (10.6.8) You have to install 7-Zip...

I was able to build and run SVGCleaner just fine on my Mac, but even though 7-Zip is installed and working (7z in the terminal works, built from sources w/ homebrew) on the PATH, SVGCleaner always errors with the "You have to install 7-Zip to use SVGCleaner" Alert box... which is especially odd because I have "Compressing" unchecked in the wizard. Is there a way around this?

EDIT: editted the wizarddialog.cpp to point to /usr/local/bin instead of /usr/bin and the alert still popped up.

Can the file checking also check the PATH in the future instead of hard coding one path in?

class attribute removed on text elements

Hi!

I have a problem that the class attribute is removed on text elements. The class attribute is very important for the usage of SVG I try to clean.

I've tried to turn all settings to off but it is still removed.
A setting to keep specific element or attribute would be a very nice feature.

Using version 0.6.2

Example of text element:

<text stroke="none" fill="#000000" font-family="'Arial'" id="AUTOID_24591" class="15" itedo:apstype="grobject" x="279.23244094488194" y="523.8396850393701" font-size="10.000629921259844">15</text>

cleaned version:

<text stroke="none" fill="#000000" font-family="&apos;Arial&apos;" id="AUTOID_24591" itedo:apstype="grobject" x="279.23244" y="523.83969" font-size="10.00063">15</text>

Also the crappy software that generates the SVG in the first place are adding ' around the font family name....

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.