scour-project / scour Goto Github PK
View Code? Open in Web Editor NEWScour - An SVG Optimizer / Cleaner
License: Apache License 2.0
Scour - An SVG Optimizer / Cleaner
License: Apache License 2.0
Following up on #35, I found that <title>
and <desc>
(as well as <metadata>
) are purely descriptive elements, according to the SVG 1.1 specification. There already is an option to remove <metadata>
(--remove-metadata
), but not for <title>
and <desc>
.
What we could do:
<title>
and <desc>
to the same option.Any thoughts?
I'm using Scour to optimize UI elements in Firefox. On some files this appears to break.
Scour adds standalone="no" to the header. This makes the file unable to be opened in Viewnior. If used as a Firefox UI element, it also fails to render (curiously it works if opened by Firefox as a page)
I don't understand what standalone means in the context of SVGs, so I can't say if this is a valid bug.
The file in question:
menu-check-black.svg.zip
I am using inkscape 0.91 and I read in a stackexchange article about the scour tool and how it can reduce file sizes of .svg files significantly and that it was already an extension in inkscape. But I do not see it within inkscape.
Is there a windows version of scour?
Does the windows version of inkscape come with scour and I'm not seeing it?
The original script had a --remove-doctype
option [1], was it intentionally removed?
[1] https://github.com/pwfisher/scour.py/blob/master/scour.py#L3183
@codedread Hi Jeff, we need your help;)
In this Eduard (@Ede123) has added Travis and Tox support. This is for automatically testing installation and unit tests on various Python environments. Eg see the output here https://travis-ci.org/Ede123/scour/builds/120307796
Now, we can make above tests run full automatically on new/modified PRs, and immediately see if there is something bad inside, eg have a look at crossbario/txaio#59 and the test results https://travis-ci.org/crossbario/txaio/builds/118453232
For Travis integration, this repo needs to be wired up to Travis. This is easy and quick, but can only be done by repo admins.
So I would like to ask if you support these efforts?
If so, you would need an account on https://travis-ci.org/, and then go to "Settings => Webhooks => Add .. Travis"
Apparently SVGs can contain inline CSS. Firefox for example makes use of that. I don't know their purpose, but here they are.
Scour seems to escape these styles.
"
becomes
"
That doesn't seem right. attached is an example file: radio.svg.zip
Importing the old unittests (#24) uncovered an issue with non-ASCII characters
See unittests/utf8.svg
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg">
<desc>ú</desc>
</svg>
for the failing example
I found a possibility (git-replace
) to import the full history from the Launchpad repository, linking it to the GitHub commit history without rebasing (all the recent commits remain unchanged including hashes!)
In fact my fork at https://github.com/Ede123/scour contains the full history right now, see https://github.com/Ede123/scour/commits/39fb9eee021e328261075481a2addbdca2c6cf19.
I'm afraid GitHub does not support replacements in its front-end, so it will not show the combined history. However if one clones the repository locally and executes git fetch origin 'refs/replace/*:refs/replace/*'
the full history will be available and visible when doing e.g. git log
Since GitHub does not allow me to create a PR for this (since there are obviously no changes when comparing):
Shall I describe the necessary steps in detail so someone with write access to the repository can re-do the import?
Optimizing loses some elements.
Imported from Launchpad using lp2gh.
When I just type scour
, the console will show the version number and copyright notice, but it won’t terminate the Python process and return to the command line automatically. Is this intentional? Normally, I would expect that a call without any arguments either returns nothing or --help
.
Pressing control + c will also give me this output:
File "/usr/local/Cellar/scour/0.32/libexec/bin/scour", line 8, in <module> load_entry_point('scour==0.32', 'console_scripts', 'scour')()
File "/usr/local/Cellar/scour/0.32/libexec/lib/python2.7/site-packages/scour/scour.py", line 3321, in run
start(options, input, output)
File "/usr/local/Cellar/scour/0.32/libexec/lib/python2.7/site-packages/scour/scour.py", line 3295, in start
in_string = input.read()
KeyboardInterrupt
Note, I also have this when I install Scour with pip.
Importing the old unittests (#24) uncovered an issue with stripping comments via --enable-comment-stripping
See unittests/comment-beside-xml-decl.svg
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Oh look a comment -->
<!-- generated by foobar version 20120503 -->
<!-- And another -->
<svg xmlns="http://www.w3.org/2000/svg">
<!-- This comment is meant to test whether removing a comment before <svg>
messes up removing comments thereafter -->
<!-- And this one is meant to test whether iteration works correctly in
<svg> as well as the document element -->
</svg>
for the failing example
Hi Tobias,
I just found out that you're the new scour maintainer, and it's great you took over a project that was inactive for years.
One of the last changes applied to the old branch fixed a license compatibility issue with Inkscape. The question has been discussed in the Inkscape board list (https://www.mail-archive.com/[email protected]/msg00033.html) and the fix applied revision 222 (http://bazaar.launchpad.net/~scouring/scour/trunk/revision/222#scour.py).
Would you be willing to dual-license your branch too, so that we can use it in Inkscape?
Thanks in advance!
Getting an error when running the command
python scour.py -i input.svg -o output.svg
Even if i only run "python scour.py" there is the same error.
Running on Win XP, python 2.4.1, scour 0.26. It's the first time i use a python script, may be the problem is in front of the pc..
Error:
File "scour.py", line 2712
return ''.join([xml_ents[c] if c in xml_ents else c for c in str])
^
SyntaxError: invalid syntax
Imported from Launchpad using lp2gh.
The file fulltests/cgmail.svg, originally from Ubuntu 10.04's /usr/share/app-install/icons/cgmail.svg and added to trunk revision 181, renders incorrectly after being Scoured.
-- To reproduce --
Program version: trunk revision 180
Command line: ./scour.py --shorten-ids --enable-id-stripping --create-groups --renderer-workaround --indent=none -i fulltests/cgmail.svg -o fulltests/cgmail.opt.svg
Imported from Launchpad using lp2gh.
Is this project to be understood as a fork or as the official continuation of the of the original Scour project?
There are also some uncertainties that could use clarification:
The attached file was already ran through scour (0.25, default options).
If you notice, it is an svn which is full of display="none" elements. The actual image is merely two circles (one blurred) which draw a moon. I believe all the display=none elements are the hidden layers/objects from the original image.
Since these elements aren't meant to be displayed, can scour remove them? (notice how much invisible cruft the file contains...)
Imported from Launchpad using lp2gh.
I just noticed that even if I provide the --keep-unreferenced-defs
command line argument (added in e01fac8) unreferenced gradient definitions are still stripped from the output.
It does work for other elements, tough, e.g. a <rect>
.
I suggest fixing this to work for all definitions or updating the documentation accordingly since intuitively I'd assumed this option to be aimed towards gradients (which is obviously not the case).
Pinging @flosse who submitted the relevant PR #2 so he can have a look.
It seems the command line argument --shorten-ids
only shortens the IDs of referenced elements.
If an element is not referenced the ID remains unchanged.
I don't know if this ever worked, but in the current form it would only make sense to use --shorten-ids
in combination with --enable-id-stripping
.
This should probably be fixed, two options are
--enable-id-stripping
when --shorten-ids
is provided (might be unexpected for in rare cases but probably what's wanted normally)Now that the unit tests are ported over from LP and do "work", we should think about setting up proper automation using Travis and tox to run all of these for each and every commit / PR on all platforms (Pythons) we want to support.
That way, we can make best use of the unit tests, with no ongoing manual work or risk of forgetting to run the unit tests.
Hi Jeff,
I am using the qtsoftware SVG renderer to display Inkscape generated SVG content. I am using your scour tool to clean up the Inkscape files before importing.
Unfortunately, qtsoftware is a SVG tiny renderer and thus cannot use positional attributes within tspan elements, which Inkscape is using quite a lot for multiline text.
I wonder if there could be a SVG scour option to convert tspan elements into regular text elements that a SVG tiny renderer could display.
I currently do this manually by converting the parent text elements to a g (group) element that holds all the text-related attributes, then I convert all the tspan elements to text elements.
Imported from Launchpad using lp2gh.
Group collapsing won't work on groups that have an ID.
By setting --enable-id-stripping
one can achieve stripping of the ID and as a result collapsing of the group.
Question is: Should groups always be collapsed (even if they have an ID) as long as they're not referenced anywhere? Or do we keep them only to preserve the ID?
The application Inkscape is fairly the most popular free vector application on Linux and Windows. But I found no install support (or instructions) for the actual version (Scour and Inkscape)!?
I have done this now for my self (edited the scour.inkscape.py and installed the modul "six") This was nearly the first time I do something like this (so I'm not an expert).
Frankly, I want that, do not need to do again. I'm a bit wondering about this situation at all, because Scour already exist as Inkscape plugin.
Many thanks anyway to the continuing develop.
Sorry for this potentially silly question, but are there any plans to make Scour compatible with Python 3.x? Is that possible (or reasonable) at all? I must admit that I have no clue of Python, so I don't really understand the implications of my question. The only thing I know is that I had to take special measurements on our servers to be able to use Scour, as Python 2.x is not necessarily the default Python interpreter on our servers. Thanks for enlightening me! ;)
Cheers,
Joschi
(Original report: https://bugs.launchpad.net/scour/+bug/734019).
Properties seem to be inherited incorrectly in Scour. Here's the declaration in the example file gnome-dev-pcmcia.svg:
<g
[...] id="text5059"
style="[...];fill:none;stroke:black;stroke-width:0.99067909px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1">
<path
[...] id="path3675"
style="[...];fill:white;fill-opacity:1;stroke:none;[...]" />
But the path ends up with stroke:black due to incorrect inheritance rules. The text PCMCIA, described by the above-named path in the example file, is then black instead of white.
Scour version used = trunk r206
Command line used = scour.py --disable-style-to-xml -i INFILE -o OUTFILE
When writing output to stdout
, (i.e. scour -i input.svg > output.svg
) an error is thrown:
Traceback (most recent call last):
File "C:\Python3.5\lib\runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python3.5\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "E:\Temp\Downloads\Scour\scour.git\scour\scour.py", line 3360, in <module>
run()
File "E:\Temp\Downloads\Scour\scour.git\scour\scour.py", line 3356, in run
start(options, input, output)
File "E:\Temp\Downloads\Scour\scour.git\scour\scour.py", line 3349, in start
sizediff))
ValueError: I/O operation on closed file.
The list of nodes that contain length kind of attributes misses the "text" entity. Attached patch cares for that.
Imported from Launchpad using lp2gh.
(Original report in https://bugs.launchpad.net/scour/+bug/1514073)
Font-family-names like "'MyriadPro-Regular'" get converted to "'MyriadPro-Regular'" with HTML-Entitys (primary fonts with whitespaces, because single quotation marks are recommended for this by the W3C) if you save as Optimzed SVG. Tested on Windows 7 x64 and Ubuntu latest version.
Inkscape 0.91 r13725
includes Scour 0.26+r220
Also reproduced on Xubuntu 15.10 with Scour 0.31 (as a standalone script).
Test file available in the original report (unfortunately GH doesn't support SVG attachments...).
--indent=none
removes whitespace except line breaks. An additional option to also strip these last bits would be very useful for webfonts for instance.
Using relative import paths inside scour.py doesn't work when calling the script from outside the package directory:
ValueError: Attempted relative import in non-package
from .svg_regex import svg_parser
Should be
from svg_regex import svg_parser
The same for two other relative imports inside this file.
Properties seem to be inherited incorrectly in Scour. Here's the declaration in the example file gnome-dev-pcmcia.svg:
<g
[...] id="text5059"
style="[...];fill:none;stroke:black;stroke-width:0.99067909px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1">
<path
[...] id="path3675"
style="[...];fill:white;fill-opacity:1;stroke:none;[...]" />
But the path ends up with stroke:black due to incorrect inheritance rules. The text PCMCIA, described by the above-named path in the example file, is then black instead of white.
[Inferred information from bug 702423]
Scour version used = trunk r206
Command line used = scour.py --disable-style-to-xml -i INFILE -o OUTFILE
Imported from Launchpad using lp2gh.
While we're in the process of migrating data from the old repository, it might be a good time to check what else might be worth to keep. Personally I'd say the following should be considered:
There are some more things I'm less sure about (and therefore would probably drop, at least at this point; we can still bring them back in one way or another in the future if needed):
statistics.html
and statistics.xls
as well as the test files in the fulltests
folder). They're surely nice to have and show what Scour actually does, but without somebody to maintain them they're of little use.scra.py
and webscour.py
)Feel free to comment on the above and add others if I missed something!
Steps to reproduce:
python /path/to/Scour/setup.py install
as explained in readme.md
Result:
Traceback (most recent call last):
File "..\..\scour-0.32\setup.py", line 35, in <module>
verstrline = open(VERSIONFILE, "rt").read()
IOError: [Errno 2] No such file or directory: 'scour/__init__.py'
Probable source of the issue:
https://github.com/codedread/scour/blob/master/setup.py#L34-L35
VERSIONFILE
uses a relative path, so it is not found when not executed from within the package directory.
Have you considered any simplifications or changes to the workflow? Currently, the minimum input is this:
scour -i /path/to/file.svg -o /path/to/newfile.svg
However, would it not be possible to imply the -i
and -o
by default? Like this:
scour /path/to/file.svg /path/to/newfile.svg
In addition and/or alternatively, why not make -o
optional and automatically write the new file to the same directory, appended with a number, date and/or keyword to the file?
scour /path/to/file.svg
Ideally, I just want to type scour
and drag and drop into the CLI. Moreover, I would actually like to see an option for scrubbing multiple files at once.
scour /path/to/file.svg /path/to/file2.svg /path/to/file3.svg
Any thoughts?
Polylines and polygons are defined in the SVG specification as being alternate forms for paths starting with an absolute move to the first point and linetos to each of the following points. In the case of polygon, a closepath is also added.
A naive reading of this feature request would just convert "polyline points=..." into "path d=M..." and "polygon points=..." into "path d=M...Z", but the real savings is had from:
Consider this polygon, from a test case in https://bugs.launchpad.net/scour/+bug/481605/comments/3 :
<polygon fill-rule="evenodd" clip-rule="evenodd" fill="#993300" points="370.441,402.976 371.967,403.015 374.941,403.343
377.819,403.942 380.601,404.831 383.247,405.989 385.758,407.419 388.113,409.042 390.335,410.916 392.344,413.02 394.141,415.26 ..." />
A naive conversion would just do this:
A real conversion would be done before paths, and thus allow the new path to be converted as well:
which is clearly shorter.
Imported from Launchpad using lp2gh.
Follow up to #59:
As already discussed there we should order attributes by default in output.
Furthermore a semantic ordering would be preferable to increase human readability.
The challenge at hand is to find a viable way to achieve a useful attribute order, even with future SVG specifications, namespaced extensions, etc. in mind.
At the moment default attribute values are always removed. I'm interested in whether an attribute has been set or not even if it's to the default so a flag to disable this behaviour would be useful.
Is it possible to have scour support some kind of verbose output mode, where information such as "progress" is provided?
Thanks!
Imported from Launchpad using lp2gh.
The following file looses the gradient used to fill the clipping path on the outer circle when optimized with scour.
Preview: https://www.dropbox.com/s/p3axbgr9ek59gcu/gradientproblem.svg?dl=0
Download: https://www.dropbox.com/s/p3axbgr9ek59gcu/gradientproblem.svg?dl=1
Inspecting the scour svg shows that the gradient itself (liner0) is still present and used to fill the clip path, but the circle is rendered a solid white.
I tried optimizing the SVG with svgo
instead and although it did similar optimizations it didn't break the gradient.
Screenshot (original left, scour-optimized right):
The SVG was generated from a PDF file using poppler and cairo's svg renderer.
"The Apache2 license is not compatible with the GPL2, but Inkscape is distributed under terms of the latter license, so in order to distribute scour with Inkscape it needs to also be usable under GPL2/3."
https://code.launchpad.net/~bryce/scour/dual-license/+merge/219950
Is this fork intending to follow the model?
IMO, scour really deserves a better README. both visually, and content wise, as the first user experience / contact with scour will either be
--indent=none option already removes whitespace but not newlines. It would be helpful to be able to remove all insignificant whitespace from the file.
Imported from Launchpad using lp2gh.
I have an SVG file with a lot of transform="translate..."
attributes
<path d="M2662.28,2240.07c0-.19,0-0.37,0-0.56a33.91,33.91,0,0,1,.83-5.58l-6.23-4.53a41,41,0,0,0-1.48,8.45Z" transform="translate(-2650 -2215)"/>
<path d="M2657.26,2228.41l6.2,4.5a6.61,6.61,0,0,1,4.45-4.45l-4.5-6.2A10,10,0,0,0,2657.26,2228.41Z" transform="translate(-2650 -2215)"/>
<path d="M2668.92,2228.15a55.17,55.17,0,0,1,6.89-.83l0.56,0-2.22-6.84a57,57,0,0,0-9.76,1.48Z" transform="translate(-2650 -2215)"/>
I was wondering whether there will be an option to convert/remove this transform attribute..
When using flow text - as opposed to standard text - in Inkscape, it will save the SVG with flowRoot
elements, which pretty much is only understood by Inkscape itself. All browsers will fail.
It would be very nice/convenient if scour could resolve, or at least warn of this problem.
As discussed at #14 it would be nice to import the unittests from the old repository (see http://bazaar.launchpad.net/~scouring/scour/trunk/files).
Some preliminary findings:
testscour.py
(which makes use of testcss.py
and the test files in the folder unittests
)Scour munges a few paths in http://en.wikipedia.org/wiki/File:Chrome_Logo.svg to look incorrect, specifically it breaks this path:
https://gist.github.com/1102020
Imported from Launchpad using lp2gh.
Currenly, Scour by default drops precision to five digits, so a file using 7 digits of precision (not all uncommon for Adobe Illustrator files, especially dumb ones, where the whole image is in a view box somewhere 7200 units away from the coordinate system origin) will silently be degraded, without warning.
At least I would not expect lossy behaviour by default; it's non-unix:y.
Imported from Launchpad using lp2gh.
I regularly struggle with different files of the Scour project using different formatting (notably different indenting which is particularly inconvenient in Python).
I'd like to harmonize formatting across source files and adjust at least indentation.
Personally I prefer 4-space indents, but I'm open for suggestions.
Pinging @oberstet since I guess proper code formatting is important to you and you decided on the unusual 3-space indents currently used in scour.py
.
The application Sketch is a fairly popular vector application on the Mac. I hope that support could be added at some point. Just for documentary purposes, some Sketch-specific inclusions that would need to be scrubbed (I haven’t found a complete specification yet):
xmlns:sketch="http://www.bohemiancoding.com/sketch/ns"
<!-- Generator: Sketch X.Y.Z (01234) - http://www.bohemiancoding.com/sketch -->
(will be removed with --enable-comment-stripping
)<title>[...]</title>
(title of the exported Sketch object)<desc>Created with Sketch.</desc>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
<g id="[same as <title>]" sketch:type="MSLayerGroup">
[...]
</g>
</g>
sketch:alignment
(for <text>
, not supported natively)sketch:name
(only seen in <mask>
so far)sketch:type
(values: MSPage
, MSShapeGroup
, MSLayerGroup
, MSTextLayer
)scour should run on both Python 2 and 3. This can be done with some coding discipline
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.