Creating a random image and background
Posted: Thu Jan 18, 2007 1:46 pm
I've made the script to get a random image using Curl because my host has opendir() disabled but I've not been able to come up with a method for creating a random image and have a background that goes with it.
like
background1.gif
image1.gif
or
background10.gif
image10.gif
any ideas would be nice.
thanks,
mystical
like
background1.gif
image1.gif
or
background10.gif
image10.gif
any ideas would be nice.
thanks,
mystical
Code: Select all
<?php
function random_logo( $logos )
{
$total_logos = count($logos );
$current_logo = mt_rand(0, $total_logos-1);
return $logos[$current_logo];
}
$this_logo = array(
"IMG GOES HERE",
"IMG GOES HERE",
"IMG GOES HERE"
);
$image = random_logo($this_logo);
$file_info = pathinfo($image);
$ch = curl_init();
$timeout = 20;
curl_setopt ($ch, CURLOPT_URL, $image);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
$content_type = 'Content-type: ' .$image_info['extension'];
header ($content_type);
echo $file_contents;
?>