Richard Parnaby-King

Random Quote Image Generator

Nearly every forum allows it’s users to have a signature, somewhere the user can post a link to their personal or favourite website as well as quotes and images. This post will go through the steps of combining these last two so that every time the image is reloaded, a random quote is placed onto an image.

 Preview


The Code

[php]
php.net website

Extra Credit

In this simple example we have only created a white rectangle image and put text on it. There is no reason why this code cannot be expanded to allow text to be placed on any image. You could have, for example, an image of a little man holding a very big sign, then use this script to place the random quotes into the sign.

Most (of the good) forums have filters when you try to add an image from URL, throwing a wobbly when you try to upload a file that does not end in .png, .jpg or .gif. To get around this, use an .htaccess rewrite rule similar to the one below:
[c]
RewriteEngine ON
RewriteRule random-quote-image.png$ random-quote-image.php [L]
[/c]

Very simply, this will route any requests for ‘random-quote-image.png’ into the php script.