Welcome to Gaia! ::

Reply How-To Guides Guild
How to make a random quote via Php

Quick Reply

Enter both words below, separated by a space:

Can't read the text? Click here

Submit

soad524

PostPosted: Wed Aug 16, 2006 2:31 pm


function check500($num)
{if ($num >= 500)
{return 500;}
else
{return $num;}}
$quotes = array(
'Quote 1 is this.',
'Quote 2 is this.',
'Quote 3 is this.'
)
$lines = explode("n", wordwrap(('"' . $quotes[array_rand($quotes)] . '"'),
80, "n"))
for ($i = 0, $long = 0; $i < count($lines) $i++)
{ if (strlen($lines[$i]) > $long)
{$long = strlen($lines[$i])}}
$im = imagecreate(check500($long * 6 + 9), check500(count($lines) * 17 +
3))
$background = imagecolorallocate($im, 0, 0, 0)
$text = imagecolorallocate($im, 255, 255, 255)
imagefill($im, 0, 0, $background)
for ($i = 0, $l = 3; $i < count($lines) $i++, $l += 17)
{imagestring($im, 2, 5, $l, $lines[$i], $text)}
imagerectangle($im, 0, 0, (imagesx($im) - 1), (imagesy($im) - 1), $background)
imagerectangle($im, 1, 1, (imagesx($im) - 2), (imagesy($im) - 2), $text)
header('Content-Type: image/png')
imagepng($im)
imagedestroy($im)
?>


replace
quote 1 is this
quote 2 is this
quote 3 is this
with the random sext you want it to say

to add more quotes add this and change the text
'Quote 3 is this.'
PostPosted: Wed Aug 16, 2006 2:35 pm


example


function check500($num)
{if ($num >= 500)
{return 500;}
else
{return $num;}}
$quotes = array(
[color=blue]'did you know there is over 4 mil users on gaia',
'plz donate to gaia.',
'i live in the ca.'[/color]
);
$lines = explode("n", wordwrap(('"' . $quotes[array_rand($quotes)] . '"'),
80, "n"));
for ($i = 0, $long = 0; $i < count($lines); $i++)
{ if (strlen($lines[$i]) > $long)
{$long = strlen($lines[$i]);}}
$im = imagecreate(check500($long * 6 + 9), check500(count($lines) * 17 +
3));
$background = imagecolorallocate($im, 0, 0, 0);
$text = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $background);
for ($i = 0, $l = 3; $i < count($lines); $i++, $l += 17)
{imagestring($im, 2, 5, $l, $lines[$i], $text);}
imagerectangle($im, 0, 0, (imagesx($im) - 1), (imagesy($im) - 1), $background);
imagerectangle($im, 1, 1, (imagesx($im) - 2), (imagesy($im) - 2), $text);
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>

items in blue are what i changed and so should you

soad524


Snaptastic
Captain

PostPosted: Wed Oct 04, 2006 12:49 pm


How to make a Random image sig from directory.
soad524
header ("content-type: image/gif");
$path = '[color=blue]/path to folder with thed images[/color]';
$i = 0;
$imgDir = opendir ($path);
while ( $file = readdir( $imgDir ) )
{ $file_type = strrchr( $file, "." );
$is_image = eregi( "jpg|gif|png",$file_type );
if ( $file != '.' && $file != '..' && $is_image )
{ $images[$i++] = $file; }}
closedir ($imgDir);
srand( (double) microtime()*1000000 );
$image_name = $path . '/' . $images[rand( 0,sizeof( $images ) -1 )];
$imgSize = GetImageSize( $image_name );
if ( $i == 0 )
die();
readfile("$image_name");
?>

change the items in blue to the locvation with the images[/quote]

Hope you don't mind soad524, I did this to cut down on the excess threads. Thanks very much for the information! ^_^
PostPosted: Thu Jul 31, 2008 10:54 am


Thank you blaugh

The Starduster

5,100 Points
  • Tooth Fairy 100
  • V-Day 2011 Event 100
  • Pie Feeder 50
Reply
How-To Guides Guild

 
Manage Your Items
Other Stuff
Get GCash
Offers
Get Items
More Items
Where Everyone Hangs Out
Other Community Areas
Virtual Spaces
Fun Stuff
Gaia's Games
Mini-Games
Play with GCash
Play with Platinum