Okay so I have an idea on how I want to serve and cache my images. I don't know if this is the right way to do it but if it is, I'd like to know how to go about preventing abuse.
Situation:
index.php
<img src="images/cache/200x150-picture_001.jpg" />
images/cache/.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ images/image.php?f=$1 [L]
The above checks if the image exists, if not it will be rewritten to image.php
image.php PSEUDO code
get height and width from filename
resize and save image to cache folder
serve the image with content-type and readfile.
This way I'm trying to reduce HTTP requests and PHP load with readfiles. The browser gets the image/jpeg if it exists and if not it will be generated.
Eventually all images will be cached and served in the right height and width so browsers won't be downloading oversized images.
The only catch.. if you change the image url to different dimensions, you can fill up the server.
Am I doing it right, what's the right way to do it. Is there any chance of stopping this from happening?
I know this whole concept of caching has been refined a million times, please enlighten me.