There are many ways to handle image thumbnails. Sites with heavy traffic generate resized copies right after the original image is uploaded. Light traffic sites on the other hand, prefer to wait until the thumbnail is actually requested. Nette offers a few creative ways to handle this:
- You can use .htaccess to catch requests for non-existent thumbnails and redirect them to your script.
- Following the same theme, you can also use your ErrorPresenter to generate the thumbnail and override the response code (so that it’s not 404).
- An unusual solution is to use a helper and generate the thumbnail when rendering your template.
- Or simply use a presenter action.
In any of these cases, you need to decide where you’re going to store the thumbnail and how you’re going to delete/update it when the main image changes. This is where you can use the excellent built-in caching aparatus.