This example will show you how we can generate images with random backgrounds.
Let's create a new folder (webroot/sig/images/random), then upload some background images there. For instance, we'll use the following images in this example:
(380x50)
(380x39)
(400x39)
The script should randomly select any image stored in that folder. Once created such script, all we need to worry about is uploading the images that we want as random backgrounds.
So, let's create another file called random_images_signature.png and upload it to your webroot/sig folder, with the following contents:
<?php
//
// Load all Images from specified path...
//
$images_ary = array();
$handle = @opendir('./images/random');
while( $file = @readdir($handle) )
{
if( $file <> '.' && $file <> '..' )
{
$tmpary = explode('.', $file);
$extension = strtolower($tmpary[count($tmpary)-1]);
if( in_array($extension, array('gif', 'jpg', 'jpeg', 'png')) )
{
$images_ary[] = $file;
}
}
}
@closedir($handle);
if( count($images_ary) <= 0 )
{
die("Sorry, no images found!");
}
//
// Randomly select an image...
//
$random = time() % count($images_ary);
$image_info = array(
'image' => 'random/'.$images_ary[$random]
);
//
// Build the text array...
//
$image_text = array(
array(
'x' => 10,
'y' => 4,
'color' => array(0, 0, 255),
'font' => -5,
'text' => "Random Image: ".$images_ary[$random]
)
);
include('./includes/dynamic_gd_image.php');
?>This is how it looks like:

If you wish to see the random effect, just click here to pop it up and refresh the new window several times.
Creating a random signature (images)
Submitted on Mon, 2006-01-30 21:03









Recent comments
3 years 27 weeks ago
3 years 30 weeks ago
3 years 30 weeks ago
3 years 31 weeks ago
3 years 32 weeks ago
3 years 32 weeks ago
3 years 35 weeks ago
3 years 35 weeks ago
3 years 38 weeks ago
3 years 38 weeks ago