Dynamic Image Creation from Database Blob

So, here’s the scenario: I’ve got some image data stored in a MySQL database as a blob, or on S3. I want to pull that image data, “resize” the image (to create a thumbnail) and dynamically output the resulting image in the browser.

Where do I start? Any and all reading material or pointers would be great. I’m specifically stuck on the “resize the image after pulling the data” part.