kopia lustrzana https://github.com/brendabell/knittingtools
Added support for PNG files
rodzic
90a65b4e49
commit
623745be7d
|
@ -1,6 +1,8 @@
|
|||
import cairosvg
|
||||
import cgi
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
|
||||
from modules.pcgenerator import PCGenerator
|
||||
|
@ -39,7 +41,7 @@ def pcgenerator_get(handler):
|
|||
def pcgenerator_post(handler):
|
||||
|
||||
try:
|
||||
ctype, pdict = cgi.parse_header(handler.headers.getheader('content-type'))
|
||||
ctype, pdict = cgi.parse_header(handler.headers.getheader('Content-Type'))
|
||||
if ctype == 'multipart/form-data':
|
||||
query=cgi.parse_multipart(handler.rfile, pdict)
|
||||
|
||||
|
@ -52,6 +54,7 @@ def pcgenerator_post(handler):
|
|||
else:
|
||||
machine_type = query.get('machine')
|
||||
vert_repeat = query.get('vert')
|
||||
convert_to_png = query.get('png', [''])[0] == 'png'
|
||||
|
||||
generator = PCGenerator(
|
||||
handler,
|
||||
|
@ -61,8 +64,16 @@ def pcgenerator_post(handler):
|
|||
result = generator.generate()
|
||||
|
||||
handler.send_response(200)
|
||||
handler.send_header('Content-type', 'image/svg+xml')
|
||||
handler.send_header("Content-Disposition", "attachment; filename=punchcard.svg")
|
||||
filename_template = 'attachment; filename="punchcard-{}.{}"'
|
||||
|
||||
if convert_to_png:
|
||||
result = cairosvg.svg2png(bytestring=result)
|
||||
handler.send_header('Content-type', 'image/png')
|
||||
handler.send_header('Content-Disposition', filename_template.format(int(time.time()), "png"))
|
||||
else:
|
||||
handler.send_header('Content-type', 'image/svg+xml')
|
||||
handler.send_header('Content-Disposition', filename_template.format(int(time.time()), "svg"))
|
||||
|
||||
handler.end_headers()
|
||||
handler.wfile.write(result)
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
<li>Select the file to upload.</li>
|
||||
<li>Select your machine type.</li>
|
||||
<li>Enter the # vertical repeats if you need them. The # horizontal repeats will be automatically calculated based on the machine type.</li>
|
||||
<li>Check "Convert to PNG" if you'd like to download a PNG image instead of SVG.</li>
|
||||
<li>Click the Upload button.</li>
|
||||
</ul>In a few seconds, you should see a dialog prompting you for where you want to save your file. If you need more detailed instructions, keep reading below.
|
||||
|
||||
|
@ -69,6 +70,10 @@
|
|||
<output id="y" name="y" value="1"></output>
|
||||
<script>y.value=vert.value;</script></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="test-align:right">Convert to PNG image:</td>
|
||||
<td><input type="checkbox" name="png" value="png"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td colspan="2"><input type="submit" value="Upload"></td>
|
||||
|
@ -108,6 +113,8 @@
|
|||
|
||||
<p>The resulting SVG file can be imported into any application that understands SVG. You can also display the SVG in some browsers. Neither the text file or resulting SVG will be saved on this site. Be sure to keep them in a safe location so they don't get lost.
|
||||
|
||||
<p>Silhouette users have reported issues importing SVG files or having to resize the SVG in Inkscape before importing. If you have trouble with the SVG file, try checking the Convert To PNG button to see if that helps.
|
||||
|
||||
<h2>Bugs & Disclaimers</h2>
|
||||
<p>This program has only been tested using Sure Cuts A Lot on a Pazzles Creative Mighty. YMMV!
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue