class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
Your code above cannot work anyway: you are trying to instantiate a class with a file that doesn't exist. Indeed, the filename you have is the contents of the file with an image extension, it cannot possibly work.
You should instantiate the class with raw base64 data:
You should instantiate the class with raw base64 data: