grade icon indicating copy to clipboard operation
grade copied to clipboard

Work as a util server side.

Open tryggvigy opened this issue 9 years ago • 4 comments

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.

tryggvigy avatar Aug 22 '16 12:08 tryggvigy

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 avatar Aug 22 '16 18:08 nijikokun

@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.

feross avatar Aug 23 '16 10:08 feross

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...

benhowdle89 avatar Aug 29 '16 16:08 benhowdle89

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.

feross avatar Sep 12 '16 16:09 feross