[eluser]JoostV[/eluser]
You use 'SELECT albums.*' when you should be using 'a.*' => because later on in your query you reference table albums as a.
I always create one or more thumbs when an image is uploaded, and I display these whenever I need a thumb. This way, the thumbs are already on your filesystem.
Most of the times, I create
- big image
- medium image
- thumb
- square thumb, squared from the center
I set the sizes in a config file, so that I can adjust them for every app.
Creating thumbs on-the-fly is too much of a burden on your server's CPU.