Update scra.py for embed rasters, styled form
This commit is contained in:
parent
f1f0aab965
commit
9dd7f08231
2 changed files with 39 additions and 15 deletions
|
|
@ -16,8 +16,8 @@
|
|||
<p>July 5th, 2009</p>
|
||||
<ul>
|
||||
<li>added --keep-editor-data command-line option</li>
|
||||
<li>Fix Bug 395645: Keep all identified children inside a defs (Thanks Frederik!)</li>
|
||||
<li>Fix Bug 395647: Do not remove closepath (Z) path segments</li>
|
||||
<li>Fix <a href="https://bugs.launchpad.net/scour/+bug/395645">Bug 395645</a>: Keep all identified children inside a defs (Thanks Frederik!)</li>
|
||||
<li>Fix <a href="https://bugs.launchpad.net/scour/+bug/395647">Bug 395647</a>: Do not remove closepath (Z) path segments</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
|
|
|
|||
50
scra.py
50
scra.py
|
|
@ -19,6 +19,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
from mod_python import apache
|
||||
from mod_python import util
|
||||
from scour import scourString
|
||||
|
|
@ -29,17 +30,33 @@ def form(req):
|
|||
<html>
|
||||
<head>
|
||||
<title>Scrape Your SVG Files</title>
|
||||
<style type="text/css">
|
||||
#options {
|
||||
border-style: solid;
|
||||
border-width: 1px;
|
||||
border-color: black;
|
||||
padding: 5px;
|
||||
}
|
||||
label.Title {
|
||||
font-weight: bold;
|
||||
font-size: 14pt;
|
||||
}
|
||||
</style>
|
||||
</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>
|
||||
<form method="POST" action="fetch" enctype="multipart/form-data">
|
||||
<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>
|
||||
<p>Paste the SVG file below:</p>
|
||||
<textarea cols="70" rows="15" name="indoc" id="indoc"></textarea>
|
||||
<p>Or choose a SVG file to upload:<input type="file" name="upload"></input></p>
|
||||
<p>If you care about these things, update your options:</p>
|
||||
<div id="options">
|
||||
<label class="Title">Options</label><br/>
|
||||
<input type="checkbox" id="convertStyleToXml" name="convertStyleToXml" checked>Convert styles to XML attributes</input><br/>
|
||||
<input type="checkbox" id="collapseGroups" name="collapseGroups" checked>Collapse nested groups when possible</input><br/>
|
||||
<input type="checkbox" id="stripIds" name="stripIds">Strip all unused id attributes</input><br/>
|
||||
<input type="checkbox" id="simplifyColors" name="simplifyColors" checked>Simplify colors to #RGB format</input><br/>
|
||||
<label>Digits of Precision:</label>
|
||||
<select id="digits" name="digits">
|
||||
<option value="1">1</option>
|
||||
<option value="2">2</option>
|
||||
|
|
@ -52,7 +69,8 @@ def form(req):
|
|||
<option value="9">9</option>
|
||||
</select>
|
||||
</div>
|
||||
<textarea cols="80" rows="30" name="indoc" id="indoc"></textarea>
|
||||
<p>and then just click <input type="submit" value="Go"> already!</p>
|
||||
<p>For a more complete description of the options, see the <a href="http://codedread.com/scour/#options">corresponding scour page</a>.</p>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -64,12 +82,12 @@ class ScourOptions:
|
|||
style_to_xml = True
|
||||
group_collapse = True
|
||||
strip_ids = False
|
||||
digits = 5
|
||||
embed_rasters = 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"
|
||||
fs = req.form
|
||||
options = ScourOptions()
|
||||
|
||||
# interpret form options
|
||||
|
|
@ -83,5 +101,11 @@ def fetch(req, indoc,**params):
|
|||
options.simple_colors = False
|
||||
options.digits = int(params['digits'])
|
||||
|
||||
req.write(scourString(indoc,options))
|
||||
fileitem = fs['upload']
|
||||
if fileitem.filename:
|
||||
req.write(scourString(fileitem.file.read()))
|
||||
else:
|
||||
req.write(scourString(indoc,options))
|
||||
|
||||
req.write( '<!-- ' + getReport() + ' -->')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue