How to optimize code?

Post questions on how to use or achieve an effect in Inkscape.
mitchell02

How to optimize code?

Postby mitchell02 » Thu Jul 23, 2009 8:07 am

When I save as plain svg the file contains what appears to be excessive code, for example.

<path
d="M 205.28916,137.75781 L 205.28916,115.25781 L 202.27354,115.25781 C 200.28196,125.04391 192.57526,132.75061 182.78916,134.74219 L 182.78916,137.75781 L 205.28916,137.75781 z"
id="path3162"
style="fill:#007098;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />


Is there another program that I can use after I am finished with Inkscape to optimize or remove the extra numbers and unnecessary words?

Thanks for any advice.

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: How to optimize code?

Postby ~suv » Thu Jul 23, 2009 12:17 pm

Scour - an SVG scrubber
codedread wrote:Scour is an open-source Python script that will clean SVG files, removing a lot of 'cruft' that certain tools or authors embed into their documents. The goal of scour is to provide an identically rendered image (i.e. a scoured document should have no discernable visible differences from the original file)

hth, ~suv

Mitchell
Posts: 1
Joined: Wed Jul 15, 2009 9:58 am

Re: How to optimize code?

Postby Mitchell » Fri Jul 24, 2009 4:16 am

Thanks. I already tried scour. I could not get it to work on my Windows XP machine.

I installed both Python and Scour in my program files folder.
I moved the file I want to scour into scours folder.
I clicked on the scour.py program in scours folder which opened a command prompt.
I typed as per directions in the command prompt: $ python scour.py -i input.svg -o output.svg and pressed enter (replacing input and output with the name of my file)
After I press enter nothing happens except the blinking cursor moves down a line.

Is there something I missed?
Thanks for any advice.

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: How to optimize code?

Postby ~suv » Fri Jul 24, 2009 5:02 am

I don't know about XP - for me it worked 'out-of-the-box' on OS X. You need someone windows savvy for help how to setup or configure python…

Does this display the help message:

Code: Select all

python scour.py --help
Maybe you can call the python script directly (I'm not sure how to add the current dir to the command) like

Code: Select all

.\scour.py --help
or just

Code: Select all

scour.py --help
(assuming that the installation of python has added the python install dir to $PATH or whatever the windows equivalent of the search path for executable files is called)

online help: How do I run a Python program under Windows?

mitchell02

Re: How to optimize code?

Postby mitchell02 » Fri Jul 24, 2009 8:42 am

Thanks for your response.

I have three command prompts. Windows, Python, and Scour.py. I have tried them all at one point or another. Nothing has yet effected the svg file I am trying to optimize.

I tried what you said regarding a help command. The Python command prompt just kept saying syntax error.

I read that link How do I run Python program under windows. It talked about paths. I couldn't understand exactly what to do or how to do it, so I uninstalled Python from C:program files and reinstalled it to C: so far I still get no response after I enter $ python scour.py -i input.svg -o output.svg or some variation like .\scour.py -i input.svg -o output.svg.

If Scour is the only program that cleans up Inkscape files I may have to try another svg graphical editor.

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: How to optimize code?

Postby ~suv » Fri Jul 24, 2009 9:07 am

mitchell02 wrote:after I enter $ python scour.py -i input.svg -o output.svg or some variation

Did you include the '$' when you enter the code on the command line? Don't! Open a "DOS window" with "Start | Programs | Accessories | Command Prompt" (or similar, depending on your Windows version), then enter

Code: Select all

cd C:\Program Files\Scour
(use the correct path to your scour installation, including upper/lower case as shown in the explorer) to change to the installation folder of Scour and then type

Code: Select all

python scour.py --help

Don't double-click on 'scour.py' in the explorer because this will just execute the script file without any arguments (those input/output file names).

mitchell02 wrote:It talked about paths. I couldn't understand exactly what to do

From a quick look at the page I assume that the default installation process takes care of that - sorry if my previous post was confusing in this regard.

mitchell02 wrote:If Scour is the only program that cleans up Inkscape files I may have to try another svg graphical editor.

I don't know if there's one with a Windows GUI - but I didn't ask google either ;-)

mitchell02

Re: How to optimize code?

Postby mitchell02 » Fri Jul 24, 2009 10:12 am

I am having a little trouble understanding your suggestion.

Of the three command prompts (Windows, Python, or scour.py), which one do I use to optimize my svg file?

Do I type this?
$ python scour.py -i input.svg -o output.svg

or.
C:\Program Files\scour $ python scour.py -i input.svg -o output.svg

A graphical editor that I think produces cleaner code, but the editor itself is not as feature rich or intuitive to use.
http://www.perfectsvg.com/feature.asp

A list of visual editors down on the right of this page.
http://svg.startpagina.nl/

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: How to optimize code?

Postby ~suv » Fri Jul 24, 2009 7:09 pm

last try ;-)
mitchell02 wrote:Of the three command prompts (Windows, Python, or scour.py), which one do I use to optimize my svg file?
none. close them all, and open a new 'DOS Window' with the Start menu.

mitchell02 wrote:Do I type this?
$ python scour.py -i input.svg -o output.svg
or.
C:\Program Files\scour $ python scour.py -i input.svg -o output.svg
none - enter this in the newly opened command window:

Code: Select all

cd C:\Program Files\scour
python scour.py --help

Please note that the '$' is not part of the command to enter at the command prompt.

mitchell02 wrote:A graphical editor that I think produces cleaner code, but the editor itself is not as feature rich or intuitive to use
I can't comment on a specific editor - but probably a graphical one is the better suited tool for you. I'm sorry I can't teach you the basics of how to work with the command shell. But we tried, didn't we? ~suv

CarlCravens
Posts: 26
Joined: Wed May 27, 2009 7:32 am

Re: How to optimize code?

Postby CarlCravens » Sat Jul 25, 2009 12:45 am

When you double-click on scour.py, I don't think you're getting a command prompt... as a typical Unix program, not giving it a filename means it's waiting for an SVG XML structure to be entered. It doesn't expect you to do this by hand, but it expects to be opened in this mode to receive the output directly from another program. So this mode isn't useful to you.

When you double-click on python.exe, you are getting a command prompt, but it's the Python interpreter... it's expecting you to type valid Python program code. You could load scour.py here and cause it to run if you know what you're doing, but that's not how you're expected to use a Python script normally. So not useful either.

~suv has it right... how he describes it should work for you, but it'll be a little cumbersome to use.

If you'd like to be able to just type "scour -i [file] -o [file]" from any directory (folder), so that you can work in your SVG directory (this is how we experience it in Linux), that's possible and pretty easy. This page gives a very step-by-step introduction to the command shell and how to set up Python scripts to work this way...

http://www.voidspace.org.uk/python/arti ... line.shtml

mitchell02

Re: How to optimize code?

Postby mitchell02 » Sat Jul 25, 2009 7:12 am

Thank you ~suv for volunteering your time and efforts to help me.
It seems that misunderstandings are difficult to avoid when communicating through a medium that is exclusively linguistic in nature. If only you could see what I see.

I think when you refer to the

'DOS Window'
command window


you are talking about the same thing. I refer to this as the Windows command prompt.

Plus I got confused when you wrote

“Did you include the '$' when you enter the code on the command line? Don't! Open a "DOS window" with "Start | Programs | Accessories | Command Prompt" (or similar, depending on your Windows version), then enter

I thought you were telling me

Don’t open a DOS window.

My mistake.

I hope those links I provided you will lead to some kind of benefit sometime.

Thanks Carl. I am in the process of studying that link you provided.

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: How to optimize code?

Postby ~suv » Sat Jul 25, 2009 4:44 pm

mitchell02 wrote:misunderstandings are difficult to avoid when communicating through a medium that is exclusively linguistic in nature. If only you could see what I see.
Re-reading my comments I realize how unclear and easily misleading my suggestions are, my apologies for that to you and thanks to CarlCravens for the logical and well structured clarification! I am glad you didn't let me discourage you from using Scour - and thank you for the links (maybe Wikipedia's 'Comparison of vector graphics editors' could be added as another useful resource).

~suv (s/he/she/ ;-)

CarlCravens
Posts: 26
Joined: Wed May 27, 2009 7:32 am

Re: How to optimize code?

Postby CarlCravens » Sun Jul 26, 2009 1:38 pm

~suv wrote:~suv (s/he/she/ ;-)


Whoops, sorry. :) Don't suppose I'll forget that in the future now.

I might have good solution for this issue for this general issue of using Unix command-line tools on Windows, but I really haven't had time to pursue it... my wife's Windows install died yesterday and I had to accelerate my plan to upgrade her to Linux today.

I've been searching off and on for weeks a graphical "launcher" utility that will let me create simple front-ends to command-line tools, and this time I finally hit on the right combination of keywords and boring forum posts...

The Wizard's Apprentice ... http://wizapp.sourceforge.net/

It lets you write batch (or Perl, Python, etc) scripts using GUI dialogs ... not just a launcher at the beginning, but you can take input from a dialog, do some processing, and then pop up another dialog for more input or to show results. Once I get a chance to learn how it works, it should be pretty simple to write a GUI front-end to scour (and, say, uniconvertor) to make them easier for Windows users to deal with. (Heck, one could even write a front-end to a collection of front-ends for these little SVG utilities.)

I need to learn how to use it for work projects anyway, and scour just needs a handful of flags and input/output file names. I don't really use Windows, but I really understand the frustration Windows non-power-users have when they try to use traditional-style Unix tools in a Windows environment. But if someone else wanted to take this and run with it, I'd certainly cheer them on.

codedread
Posts: 3
Joined: Wed Aug 05, 2009 3:28 am

Re: How to optimize code?

Postby codedread » Wed Aug 05, 2009 3:31 am

I'm sorry you are still having trouble getting scour to work in Windows. This is one area where I will try to focus in future releases.

It may interest you to try the online web-based version of scour: http://www.planetsvg.com/tools/scour/scra.py/form

Here you can paste your file in (or select it to upload) and just click "Go". The browser will then show you the scoured SVG file and you can then save it (View source, copy/paste, etc).

Hope that helps,
Jeff Schiller

codedread
Posts: 3
Joined: Wed Aug 05, 2009 3:28 am

Re: How to optimize code?

Postby codedread » Thu Aug 06, 2009 1:27 am

An update since yesterday: I added Scour as an extension in Inkscape 0.47 (not yet released). I also have the extension available for download at http://codedread.com/scour/#downloads - simple download the zip and unzip it into your Inkscape extensions/ folder. Then you should be able to Save As and pick "Scoured SVG (*.svg)".

Note that scour does a lot of number crunching. For big files, this might take a long time (a 2.5MB file takes 5 minutes on my machine).


Return to “Help with using Inkscape”