Removed some redundant statements, fixed some coding style inconsistencies. Also significantly changed logic for some parts, which may or not be acceptable in your mind.
I tried to keep commits as small as possible, which is why there are so many. I can squash them if you prefer fewer.
Removed redundant if
Removed repeated create cache dir
Moved is_writable check to the top (fail early)
Prefer isset over error suppression
Instead of relying on the file extension, detect the type from the image
Coding style (consistency)
Initialize variable for good measure. Renamed variable as verb form.
Removed redundant conditional doing the same work twice
Removed redundant nested folder structure
Fixed path reference (cut-n-paste bug)
Syntax error fixed (bleeding quote)
Make sure the source file is readable and an image
Resolving file extension no longer required
No alpha save for 1-bit png's
Fixed 404 response