I had this problem for a certain period of time, my problem with the code was that I did not use the destroy function:
$im->destroy();
When the destroy function is called, it deletes temporary files created in the /tmp . This is for PHP, and maybe this will help someone.
source share