Page 1 of 1

Random Image Generator In PHP

Posted: Sun Mar 26, 2006 10:09 pm
by znad
Random Image Generator In PHP

Here is a small and basic example of generating random images through PHP!

[PHP]//This line prevents a regular pattern of numbers to be generated.
Srand(microtime() * 1000000);
//This line creates a random integer between 1 and 3
$num = rand(1,3);

//Next we will use a switch statement to display the random image.
Switch($num)
{
case 1: $link=”1”; $img=”images/img1.jpg”; break;
case 2: $link=”2”; $img=”images/img2.jpg”; break;
case 3: $link=”3”; $img=”images/img3.jpg”; break;
}

//Now we will echo the dynamic content.
echo””$link”><img”; [/PHP]

Posted: Tue Mar 28, 2006 1:12 am
by vn29
is it resize image??

Posted: Tue Mar 28, 2006 8:55 am
by Lixas
no, exact this script takes one of 3 images and post it to site. Using this script you can use it for random banners or something like that

Posted: Thu Mar 30, 2006 11:23 pm
by vn29
oh i knew what is this for . thank you

Posted: Fri Mar 31, 2006 12:23 pm
by kaos_frack
you can make it with javascript also

and by the way why do you need this?
do you want to use it for checking for humans?
i mean ask them to enter the code that is in the image?

if yes, then i should say that this not a very good idea
you better generate images with php and fill it with random text
and random numbers

Posted: Fri Mar 31, 2006 2:48 pm
by Mizo
its nice to put this script i use it but with more pix

Posted: Fri Apr 14, 2006 11:28 am
by Whatevakid
Lol
I find PHP So easy and hard at the same time :oops:

Posted: Sun Apr 16, 2006 5:26 pm
by uz
can i add this code to my template in joomla? will it work