Could be running out of memory if you're not completely cleaning up all image resources before moving on to the next one (assuming they're all running in the same script?).
But yeah: resizing and saving them on upload would be a lot more efficient both memory- and time-wise, I think.