I have built a plugin that will auto-generate an image based on some variables in the post the user is writing. They have the ability then to set some colors and stuff to make the image look nice. When the user is happy with this image they can click "save". This will call admin ajax and uses
wp_insert_attachment to create the image. This much is working.
As part of the ajax call I also call