Save dynamically generated image to IPFS

Iโ€™m writing a dapp that can create NFTs with procedurally generated images. The images are drawn in a canvas element in javascript. How can I get the image data and save it as an image file on IPFS?

I donโ€™t know how you get the image data, but after you have the image data you can use this for example to save it from a cloud function: https://docs.moralis.io/moralis-server/cloud-code/cloud-functions#ipfs

Iโ€™m getting the following error when trying your suggestion:

Uncaught (in promise) TypeError: Moralis.Cloud.toIpfs is not a function

Has the syntax changed?

did you update to the latest Moralis server version?