grade
grade copied to clipboard
Work as a util server side.
Awesome tool! It would be very useful if Grade could work with node as well.
Example usecase:
- Process user profile photos in a background job and extract gradients
- Save the gradients to a database
- Serve gradients as placeholders until actual profile pic loads.
For some applications it could be too expensive to calculate the gradients on the client.
You could use node-colour-extractor for this, get the top two colours that are used and store those for values for a gradient.
@nijikokun Thanks for the link to node-colour-extractor. One advantage this library has over that other one is no native dependency. That means no compilation step on install.
I'm totally on board with this, just trying to think how I could adapt Grade to work on the server, without adding too much bloat to the client-side library....
Maybe a sub-project? Happy to hear suggestions...
I actually want to use this in an Electron app, so I don't need node support since the DOM is available.
But I want to interact with this as a pure function rather than via the DOM. I want to pass in an image as a Buffer (i.e. Uint8Array) and get back the colors. Then I can set them in the DOM however I like.
That might be a good start. Once this new API exists, then you can just support a canvas option that allows the user to optionally pass in their own canvas implementation, like https://www.npmjs.com/package/canvas. If this parameter isn't specified, then you can just use window.canvas like you currently do.