<?php
$pic = array (
'http://link-to-image.jpg',
'http://link-to-image2.jpg',
'http://link-to-image3.jpg',
'http://link-to-image4.jpg',
);
$i = rand(0,count($pic)-1);
$currPic = $pic[$i];
function getExt($img='')
{
$pos = strrpos($img,'.');
$ext = substr($img,$pos+1,strlen($img));
if ($ext === 'jpeg') {
$ext = 'jpg';
}
return strtolower ($ext);
}
function errorImg($pic='')
{
$img = imagecreatetruecolor (150,30);
$bgc = imagecolorallocate ($img,255,255,255);
$tc = imagecolorallocate ($img,0,0,0);
imagefilledrectangle ($img,0,0,150,30,$bgc);
imagestring ($img,1,5,5,'Error Loading '.$pic,$tc);
return $img;
}
$ext = getExt($currPic);
if ($ext == 'jpg') {
if (! ($img = @imagecreatefromjpeg ($currPic))) {
$img = errorImg($currPic);
}
header ('Content-Type: image/jpeg');
imagejpeg ($img);
} elseif ($ext == 'gif') {
if (! ($img = @imagecreatefromgif ($currPic))) {
$img = errorImg($currPic);
}
header ('Content-Type: image/gif');
imagegif ($img);
} elseif ($ext == 'png') {
if (! ($img = @imagecreatefrompng ($currPic))) {
$img = errorImg($currPic);
}
header ('Content-Type: image/png');
imagepng ($img);
}
imagedestroy ($img);
?>