Shenrui-Ma/video-regen-recipes / templates/drawing-process/svg-redraw-comparison
svg-redraw-comparison
Unverified用参考图制作高精度 SVG 临摹绘制过程视频,交付纯 SVG 网页、独立 SVG 和原图对照 MP4。禁止 Canvas、位图嵌入与外链,按构图、线稿、固有色、阴影、高光、细节重放;横图上下、竖图左右合成。
| File | Kind | Size |
|---|---|---|
| LICENSE | other | 1.1 KB |
| LICENSES.md | markdown | 998 B |
| README.md | markdown | 2.5 KB |
| SKILL.md | skill md | 3.8 KB |
| assets/manifest.json | config | 320 B |
| assets/reference.png | binary | 2.7 MB |
| examples/demo.html | other | 30.1 KB |
| examples/foundations.svg | other | 597.0 KB |
| examples/preview.mp4 | binary | 3.2 MB |
| examples/redraw.svg | other | 15.6 MB |
| examples/regions.json | config | 6.7 KB |
| examples/validation.json | config | 2.1 KB |
| profile.json | config | 2.2 KB |
| prompts/author-original.prompt.txt | markdown | 1.2 KB |
| prompts/redraw.prompt.txt | markdown | 1.2 KB |
| references/validation.md | markdown | 1.2 KB |
| references/workflow.md | markdown | 5.0 KB |
| scripts/_contours.py | script | 1.3 KB |
| scripts/_regions.py | script | 1.2 KB |
| scripts/_validate_svg.py | script | 1.5 KB |
| scripts/build_demo.py | script | 5.9 KB |
| scripts/clean_png.py | script | 2.1 KB |
| scripts/export_video.cjs | script | 6.1 KB |
| scripts/package_demo.py | script | 3.4 KB |
| scripts/trace_reference.py | script | 5.0 KB |
| sources.md | markdown | 1.7 KB |
| tests/check_player.cjs | script | 3.9 KB |
| tests/test_pipeline.py | script | 4.2 KB |
| web/load-art.js | script | 3.2 KB |
| web/player.css | other | 738 B |
| web/player.js | script | 2.3 KB |
tests/test_pipeline.py
View on GitHubimport hashlib,importlib.util,json
from pathlib import Path
import struct,sys,tempfile,unittest,zlib
ROOT=Path(__file__).resolve().parents[1]
sys.path.insert(0,str(ROOT/'scripts'))
from clean_png import clean,parse,chunk,SIGNATURE
from _contours import contours
from _regions import read_regions
from _validate_svg import read_contours
from package_demo import package_page
class PipelineTests(unittest.TestCase):
def test_lossless_png_cleanup(self):
raw=b'\0'+bytes([10,20,30])*2
original=SIGNATURE+chunk(b'IHDR',struct.pack('>IIBBBBB',2,1,8,2,0,0,0))+chunk(b'tEXt',b'note\0fixture')+chunk(b'IDAT',zlib.compress(raw))+chunk(b'IEND',b'')
output=clean(original)
self.assertEqual([k for k,_ in parse(output)],[b'IHDR',b'IDAT',b'IEND'])
self.assertEqual(zlib.decompress(b''.join(v for k,v in parse(output) if k==b'IDAT')),raw)
def test_boundary_is_closed(self):
path,count=contours({0:1,1:3,3:2,2:0},1)
self.assertEqual(count,1);self.assertEqual(path,'M0 0h1v1h-1v-1z')
def test_reference_bound_regions(self):
with tempfile.TemporaryDirectory() as tmp:
p=Path(tmp)/'regions.json';p.write_text(json.dumps({'width':2,'height':1,'reference_sha256':hashlib.sha256(b'fixture').hexdigest(),'regions':[{'id':'background','polygon':[]}]}))
self.assertEqual(read_regions(p,2,1,b'fixture'),[('background',[])])
with self.assertRaises(ValueError):read_regions(p,2,1,b'other')
def test_bad_region_geometry_rejected(self):
with tempfile.TemporaryDirectory() as tmp:
p=Path(tmp)/'r.json';p.write_text(json.dumps({'width':2,'height':1,'reference_sha256':hashlib.sha256(b'f').hexdigest(),'regions':[{'id':'background','polygon':[]},{'id':'subject','polygon':[[0,0],[3,0],[1,1]]}]}))
with self.assertRaises(ValueError):read_regions(p,2,1,b'f')
def valid(self):
return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2 1"><g id="complete-vector-art"><g data-region="background"><path fill="#aabbcc" d="M0 0h2v1h-2z"/></g></g></svg>'
def test_vector_validation(self):
read_contours(self.valid(),2,1,['background'])
with self.assertRaises(ValueError):read_contours(self.valid(),2,1,['another'])
def test_raster_and_active_content_rejected(self):
for node in ['<image href="data:image/png;base64,AAAA"/>','<script/>','<foreignObject/>']:
with self.assertRaises(ValueError):read_contours(self.valid().replace('</svg>',node+'</svg>'),2,1,['background'])
with self.assertRaises(ValueError):read_contours(self.valid().replace('fill="#aabbcc"','onload="alert(1)" fill="#aabbcc"'),2,1,['background'])
def test_published_demo_is_lightweight_with_verified_local_vectors(self):
text=(ROOT/'examples/demo.html').read_text()
self.assertLess(len(text.encode()),200000)
for marker in ['<canvas','<img','<image','<foreignObject','data:image','<script src=','http://','https://']:
if marker=='http://':
self.assertNotIn(marker,text.replace('http://www.w3.org/2000/svg',''))
else:self.assertNotIn(marker,text)
self.assertIn('window.replay=',text)
import re
manifest=json.loads(re.search(r'<script type="application/json" id="art-manifest">(.*?)</script>',text).group(1))
for name in ['redraw.svg','foundations.svg']:
self.assertEqual(hashlib.sha256((ROOT/'examples'/name).read_bytes()).hexdigest(),manifest[name])
def test_packaging_keeps_paths_and_rejects_mismatch(self):
with tempfile.TemporaryDirectory() as tmp:
root=Path(tmp);source=root/'source.svg';source.write_text(self.valid().replace('<path fill=','<path id="tone-1" fill='))
path='<path id="tone-1" fill="#aabbcc" d="M0 0h2v1h-2z"/>'
art='<svg id="art" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2 1"><g id="construction"/><g id="flat-colors"/><g id="ink"/><g id="final-contours"><g data-stage="shadow">'+path+'</g></g></svg>'
page='<html><div class="frame">'+art+'</div><script>oldPlayer()</script></html>'
out=root/'new/demo.html';info=package_page(page,source,out)
self.assertLess(info['html_bytes'],200000);self.assertFalse(info['simplified'])
self.assertEqual((out.parent/'redraw.svg').read_bytes(),source.read_bytes())
self.assertNotIn('M0 0h2v1h-2z',out.read_text())
with self.assertRaisesRegex(ValueError,'paths differ'):package_page(page.replace('#aabbcc','#ffffff'),source,root/'bad/demo.html')
if __name__=='__main__':unittest.main()
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |