willnorris / imageproxy

A caching, resizing image proxy written in Go
Apache License 2.0
3.53k stars 481 forks source link

support SVG output #122

Open willnorris opened 6 years ago

willnorris commented 6 years ago

here's an interesting article about using SVGs for image previews/placeholders: https://jmperezperez.com/svg-placeholders/

I'm not sure if there is a pure Go library to do something like this, but if so, it would certainly be an interesting feature to add.

aslakr commented 6 years ago

There seem to be a pure go implementation of potrace called gotrace

koszta commented 5 years ago

https://github.com/fogleman/primitive

willnorris commented 5 years ago

So I've got a pretty good working version of this, including SVG output, in the primitive branch.

You can see a live demo at https://imageproxy.willnorris.com/x,p50:0,svg,s5ErGX8tP-RIhwUGsU3ZzzpHAtTyAe4UaIXWVDvc7Inc/https:/live.staticflickr.com/7866/46197994095_d9bbc25e3f_b.jpg

The biggest problem right now is just that this is incredibly CPU intensive. For example, I was able to recreate this image here on my local machine after several minutes, but ended up giving up on my Google Cloud Run instance after a while, since it only has a single CPU and 256 MB of RAM. I may try beefing that up, just to see how long it would take.

Before merging this into master, I think we'll need to hide it behind a flag, disabled by default, since the risk for abusing someone's server is just so high. Realistically, the only way to safely allow this is likely to require signatures on all requests, or to set some strong upper limits on how much resources a single request can consume. And I'm not really confident in that.

In any event, it's fun to play with, and was actually really easy to implement!

willnorris commented 5 years ago

I was finally able to generate it on Google Cloud Run: https://imageproxy.willnorris.com/x,p2000:6,png,spgJ-QGIOcbeYaEN-HPhtUbfS9vaoQ5JvExGt88TaP5E=/https:/live.staticflickr.com/7866/46197994095_d9bbc25e3f_b.jpg

(bumped GCR to 2 GB memory, and 15 minute request timeout... took about 10 minutes to generate)