qrohlf / trianglify

Algorithmically generated triangle art
http://qrohlf.com/trianglify/
GNU General Public License v3.0
10.08k stars 669 forks source link

Canvs-based generation and image export methods (PNG, JPEG) #6

Closed tdhsmith closed 10 years ago

tdhsmith commented 10 years ago

Refactored and added a host of methods for drawing without utilizing SVG, including drawing to a page canvas and creating PNG/JPEG/++ data URIs via dummy canvas. Now image export should be secure and supported in a much wider array of browsers (incl. Safari 5+).

qrohlf commented 10 years ago

Thanks for this. I spent a good amount of time playing with options for generating and converting with canvas. Unfortunately, it doesn't seems like canvas is able to handle the noise filter in any of the browsers I tried (seems like you ran into this too). I'd like all of the output formats of Trianglify to be visually identical, so I'm not going to add the canvas methods to the library.

I like how you split the polygon generation and svg generation out into two methods, and I think that this is a good compromise - anyone who wants to render to something other than an svg has access to the geometry now, so your canvas stuff can be implemented by end users without modifying the library code.

Moving forward, I'm looking into hooking into the Cloud Convert (https://cloudconvert.org) to convert svgs to pngs in the demo app. Their converter can produce pixel-perfect png versions of the SVG output, which is why I prefer it over the canvas method.