mesh-gradient.js icon indicating copy to clipboard operation
mesh-gradient.js copied to clipboard

Generate as a Image

Open frigopedro opened this issue 3 years ago • 5 comments

Hi, I would like to now if there is a way to generate this mesh gradient as a png file

frigopedro avatar Aug 28 '22 15:08 frigopedro

Hi, @pedriin1 Currently no, but it is easy to integrate. Feel free to create PR.

Snippet from my other project - https://github.com/anup-a/meshy/blob/main/src/lib/utils/downloadImage.js

import { saveAs } from "file-saver";

const downloadImage = (filename) => {
  const canvas = document.getElementById("gradient-canvas");

  canvas.toBlob(function (blob) {
    saveAs(blob, filename + ".png");
  });
};

export default downloadImage;

anup-a avatar Aug 28 '22 15:08 anup-a

Oh nice, is there a way to create a lambda to return a mesh gradient as an image passing colors as parameter??

frigopedro avatar Aug 28 '22 16:08 frigopedro

If I understand correctly you want to create a hosted API which generates a png image.

Should be very straightforward with this library. Let me know if you face any problems.

anup-a avatar Aug 28 '22 16:08 anup-a

Yes, I want to create a lambda in aws that generates a png images. I can`t do it because mesh is based on html, it must be event driven. To generate a canvas inside javascript its a little bit difficult. Its there a function that export mesh as png?

frigopedro avatar Aug 28 '22 23:08 frigopedro

Currently, it doesn't support server-side rendering. I can definitely give it a shot with node-canvas but I'm not too sure about how well it works.

anup-a avatar Aug 29 '22 12:08 anup-a