fogleman / primitive

Reproducing images with geometric primitives.
https://primitive.lol/
MIT License
12.35k stars 608 forks source link

SVG Export broken when setting mode to polygon #44

Closed technopagan closed 6 years ago

technopagan commented 7 years ago

It seems that SVG export is currently broken when applying the "-m 8" switch for polygon mode. PNGs render just fine, but when switching to SVG, the resulting XML is almost empty, aka no polygons are declared:

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="680" height="1024">
<rect x="0" y="0" width="680" height="1024" fill="#797261" />
<g transform="scale(4.000000) translate(0.5 0.5)">

</g>
</svg>

Tested with "kodim19" test image (http://optipng.sourceforge.net/pngtech/corpus/kodak/kodim19.png) using the following switches: "primitive -i kodim19.png -o kodim19_primitive.svg -n 10 -m 8". My environment is WSL, Linux Subsystem for Windows, Ubuntu 16.04 based, Fish shell, Golang v. 1.7.4 installed via LinuxBrew)

Original Test Image: kodim19

PNG output for -m 8 polygons: kodim19_primitive

As you can see, other simple SVG shapes export just fine. Here's an example with -m 0 (Mixed mode): "primitive -i kodim19.png -o kodim19_primitive.svg -n 10 -m 0". Notice how the lines in which polygons should have been declared stay empty:

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="680" height="1024">
<rect x="0" y="0" width="680" height="1024" fill="#797261" />
<g transform="scale(4.000000) translate(0.5 0.5)">
<ellipse fill="#322100" fill-opacity="0.501961" cx="100" cy="255" rx="78" ry="78" />
<g transform="translate(105.514796 130.100027) rotate(280.849337) scale(59.841250 23.290682)"><ellipse fill="#ffe0ac" fill-opacity="0.501961" cx="0" cy="0" rx="1" ry="1" /></g>
<ellipse fill="#f1c892" fill-opacity="0.501961" cx="20" cy="157" rx="37" ry="37" />
<ellipse fill="#aeaba8" fill-opacity="0.501961" cx="152" cy="71" rx="32" ry="52" />
<g transform="translate(18.213148 240.040670) rotate(137.721049) scale(46.473918 22.640788)"><ellipse fill="#342b03" fill-opacity="0.501961" cx="0" cy="0" rx="1" ry="1" /></g>
<ellipse fill="#3b3512" fill-opacity="0.501961" cx="159" cy="195" rx="47" ry="31" />
<ellipse fill="#4e5e7b" fill-opacity="0.501961" cx="57" cy="6" rx="79" ry="79" />

<rect fill="#6d7174" fill-opacity="0.501961" x="14" y="72" width="84" height="56" />
</g>
</svg>
linkerlin commented 6 years ago

@technopagan see PR #55 acd