Make a PHP document look like an image document
7th Oct 2007Making images in PHP is easy using the GD addon that comes with PHP. But how can we make the extension look like a real image?
Never doubt
Good ole' mod_rewrite is at hand, so then how can we do this?
The code
.htaccess
RewriteEngine On
# let the server know that we were reached via /xyz and not
# via the physical path prefix /abc/def
RewriteBase /
# now the rewriting rules
RewriteRule ^img/(.*)\.png$ image.php?a=$1 [L]
# let the server know that we were reached via /xyz and not
# via the physical path prefix /abc/def
RewriteBase /
# now the rewriting rules
RewriteRule ^img/(.*)\.png$ image.php?a=$1 [L]
The example
You could then have the following http://myphpdigest.com/img/hello.png
Change the hello part to anything you want and watch the text change!
Conclusion
This is great for such things as dynamic signatures, and you can add them to forums, as some have limits to what extensions you can have, several problems solved.