In general, if you are programmatically generating a picture (gif/whatever) then you will be creating a Media Object which can be stored in data tables.
This (very old) post of mine gives an example of creating media in code, and a search of the docs will explain how to store it :
You do also have access to your own private “/tmp” but this is ephemeral and files stored there may not survive outside of the server call that put them there, so be careful if using this.