| ▲ | iamcalledrob 2 hours ago | |||||||||||||||||||||||||||||||
As a designer, I've built variants of this several times throughout my career. The author's approach is really good, and he hits on pretty much all the problems that arise from more naive approaches. In particular, using a perceptual colorspace, and how the most representative colour may not be the one that appears the most. However, image processing makes my neck tingle because there are a lot of footguns. PNG bombs, anyone? I feel like any library needs to either be defensively programmed or explicit in its documentation. The README says "Finding main colors of a reasonably sized image takes about 100ms" -- that's way too slow. I bet the operation takes a few hundred MB of RAM too. For anyone that uses this, scale down your images substantially first, or only sample every N pixels. Avoid loading the whole thing into memory if possible, unless this handled serially by a job queue of some sort. You can operate this kind of algorithm much faster and with less RAM usage on a small thumbnail than you would on a large input image. This makes performance concerns less of an issue. And prevents a whole class of OOM DoS vulnerabilities! As a defensive step, I'd add something like this https://github.com/iamcalledrob/saferimg/blob/master/asset/p... to your test suite and see what happens. | ||||||||||||||||||||||||||||||||
| ▲ | jaen an hour ago | parent | next [-] | |||||||||||||||||||||||||||||||
I really wish people would read the article, the library does exactly this: > Okmain downsamples the image by a power of two until the total number of pixels is below 250,000. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | latexr 2 hours ago | parent | prev [-] | |||||||||||||||||||||||||||||||
> I've built variants of this several times throughout my career. Got any to share? A self-contained command-line tool to get a good palette from an image is something I’d have a use for. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||