How to serve dynamic image for NFT

I’m writing a dapp that allows the user to generate ERC1155 NFTs. I’m running into the following problem:

Initially, I was planning to have the image generated dynamically on the browser, then saved on IPFS. Then, the IPFS filename is included as URI in the metadata of the NFT during the minting process. The problem is that the IPFS file needs to be created before the NFT is minted. This is bad because a malicious hacker could generate a lot of IPFS files, without actually minting any NFTs.

The only solution I can think of is to skip IPFS altogether and have the images generated and served dynamically. My question is this: Can I create a Moralis cloud function that serves dynamically generated PNG files?

Are there are any other possible solutions?

Any help would be greatly appreciated.