Only process points if there is an even number. Update web-based scour script to process options and rename to scra.py
This commit is contained in:
parent
b9a9020feb
commit
a4dbc37ba9
4 changed files with 438 additions and 46 deletions
347
fulltests/woman_in_red.svg
Normal file
347
fulltests/woman_in_red.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 142 KiB |
6
scour.py
6
scour.py
|
|
@ -1325,7 +1325,11 @@ def parseListOfPoints(s):
|
|||
points = []
|
||||
while i < len(nums):
|
||||
x = SVGLength(nums[i])
|
||||
y = SVGLength(nums[i+1])
|
||||
# if we had an odd number of points, return empty
|
||||
if i == len(nums)-1: return []
|
||||
else: y = SVGLength(nums[i+1])
|
||||
|
||||
# if the coordinates were not unitless, return empty
|
||||
if x.units != Unit.NONE or y.units != Unit.NONE: return []
|
||||
points.append( (str(x.value),str(y.value)) )
|
||||
i += 2
|
||||
|
|
|
|||
86
scra.py
Normal file
86
scra.py
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Scour Web
|
||||
#
|
||||
# Copyright 2009 Jeff Schiller
|
||||
#
|
||||
# This file is part of Scour, http://www.codedread.com/scour/
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from mod_python import apache
|
||||
from mod_python import util
|
||||
from scour import scourString
|
||||
from optparse import OptionParser
|
||||
|
||||
def form(req):
|
||||
return """<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Scrape Your SVG Files</title>
|
||||
</head>
|
||||
<body>
|
||||
<form method="POST" action="fetch">
|
||||
<p>Scra.py uses <a href="http://codedread.com/scour/">Scour</a> to clean SVG files of unnecessary elements and attributes attempting to reduce file size and complexity without a loss in visual quality. For full details, please see the Scour <a href="http://codedread.com/scour/">home page</a>.
|
||||
<p>Paste the SVG file below and click <input type="submit" value="Go!"> or set some <span>Options</span> first. For a more complete description of the options, see the <a href="http://codedread.com/scour/#options">corresponding scour page</a>.</p>
|
||||
<div id="options"><ul>
|
||||
<input type="checkbox" id="convertStyleToXml" name="convertStyleToXml" checked>Convert styles to XML attributes</input>
|
||||
<input type="checkbox" id="collapseGroups" name="collapseGroups" checked>Collapse nested groups when possible</input>
|
||||
<input type="checkbox" id="stripIds" name="stripIds">Strip all unused id attributes</input>
|
||||
<input type="checkbox" id="simplifyColors" name="simplifyColors" checked>Simplify colors to #RGB format</input>
|
||||
<label>Digits of Precision</label>
|
||||
<select id="digits" name="digits">
|
||||
<option value="1">1</option>
|
||||
<option value="2">2</option>
|
||||
<option value="3">3</option>
|
||||
<option value="4">4</option>
|
||||
<option value="5" selected>5</option>
|
||||
<option value="6">6</option>
|
||||
<option value="7">7</option>
|
||||
<option value="8">8</option>
|
||||
<option value="9">9</option>
|
||||
</select>
|
||||
</div>
|
||||
<textarea cols="80" rows="30" name="indoc" id="indoc"></textarea>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
# defaults
|
||||
class ScourOptions:
|
||||
simple_colors = True
|
||||
style_to_xml = True
|
||||
group_collapse = True
|
||||
strip_ids = False
|
||||
digits = 5
|
||||
|
||||
# params are the form elements (if a checkbox is unchecked it will not be present)
|
||||
def fetch(req, indoc,**params):
|
||||
req.content_type = "image/svg+xml"
|
||||
options = ScourOptions()
|
||||
|
||||
# interpret form options
|
||||
if not params.has_key('convertStyleToXml'):
|
||||
options.style_to_xml = False
|
||||
if not params.has_key('collapseGroups'):
|
||||
options.group_collapse = False
|
||||
if params.has_key('stripIds'):
|
||||
options.strip_ids = True
|
||||
if not params.has_key('simplifyColors'):
|
||||
options.simple_colors = False
|
||||
options.digits = int(params['digits'])
|
||||
|
||||
req.write(scourString(indoc,options))
|
||||
|
||||
45
web.py
45
web.py
|
|
@ -1,45 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Scour Web
|
||||
#
|
||||
# Copyright 2009 Jeff Schiller
|
||||
#
|
||||
# This file is part of Scour, http://www.codedread.com/scour/
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from mod_python import apache
|
||||
from scour import scourString
|
||||
|
||||
def form(req):
|
||||
return """<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Scour it!</title>
|
||||
</head>
|
||||
<body>
|
||||
<form method="POST" action="fetch">
|
||||
<p>Paste the SVG file here</p>
|
||||
<textarea cols="80" rows="30" name="indoc" id="indoc"></textarea>
|
||||
<p>Click "Go!" to Scour</p><input type="submit" value="Go!></input>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
def fetch(req,indoc):
|
||||
req.content_type = "image/svg+xml"
|
||||
req.write(scourString(indoc))
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue