Free web development scripts for the webmasterDevelopment Scripts


 social media marketing services
 Site Navigation
Clicky Web Analytics
 o Development Scripts
 o Text Only Edition
 o PHP.net News
 o Tutorials
 o Register an account
 o New entries this week
 o Affiliates/Links
 o Contact Us
 o About us
 o Advanced Search

 Browse Path
 o 1 user online
 o Most users online: 67
 o Home
  o PHP
   o Random
    o Script

 Member Login
User Name
Password

 Standards
Valid XHTML 1.0!
Valid 
CSS!

 Recommended Links
 o PHP Freaks
 o Paper Free Invoicing
 o Tutorials
 o Expired Domain Crawler

Random Futurama Quote with Character (Rated 5)

Description:

Display a random script from the Hit TV show futurama in your signature!!
This script creates the random character image, and a string as an image from a text file.

GD Image library needs to be installed on the server you intend to host this on.

Code starts here


<?PHP
// This is going to output the image as a PNG
header ("Content-type: image/png");

// Randomise seed
srand((float)microtime()*10000000);

// Random image function
function random_image($dir = './')
{
$allowed_types = array('gif');
if(!
$dh = @opendir($dir))
die(
'Unable to open directory.');
else
{
while((
$file = readdir($dh)) !== false)
{
if(
$file == '.' || $file == '..')
continue;

// check extension
list($name,$ext) = explode('.',$file);
if(!
in_array(strtolower($ext),$allowed_types))
continue;
else
$images[] = $file;
}

$key = array_rand($images);
return
$dir . '/' . $images[$key];
}
}

$image = random_image();

// get contents of a file into a string
$filename = "quotes.txt";
$handle = fopen ($filename, "r");
$contents = fread ($handle, filesize ($filename));
fclose ($handle);

$quotes = explode("<hr>",$contents) ;

$key = rand(0,count($quotes)-1) ;

$lines = explode("\n",$quotes[$key]) ;

$largestLine = 0 ;
$count = count($lines) ;
for (
$i = 0 ; $i < $count ; $i++)
{
if (
strlen($lines[$i]) > $largestLine)
$largestLine = strlen($lines[$i]) ;
}

$character = getImageSize($image);

$pxTMP = ($largestLine * 6.5);
$px = $pxTMP + + $character[0] ;

$py = (($count+1) * 15);
if (
$py < $character[1])
$py = $character[1] ;

$fullImage = @imagecreate($px,$py);

$characterImage = @imagecreatefromgif($image);

imagecopyresized($fullImage,$characterImage,0,0,0,0,$character[0],$character[1],$character[0],$character[1]);


$im = @imagecreate($px, $py) or die ("Cannot Initialize new GD image stream");

$background_color = imagecolorallocate ($im, 255, 255, 255);

$trans=imagecolortransparent($im,$background_color);


$text_color = imagecolorallocate ($im, 0, 0, 0);
for (
$i = 0 ; $i < count($lines) ; $i++)
{
imagestring ($im, 2, 5, ($i+1)*15, $lines[$i], $text_color) ;
}

imagecopyresized($fullImage,$im,$character[0],0,0,0,$pxTMP,$py,$pxTMP,$character[1]);

$trans=imagecolortransparent($fullImage,$background_color);

imagepng ($fullImage);

?>

See it working here http://www.devscripts.net/futurama/siggy.php

Last Edited: August 29, 2003, 10:45 pm


Submitted by Devscripts on 29-08-2003 22:45


Recent Additions (from all categories)

(PHP) T Shirt Printing Software

(PHP) Youtube Video Organizer Script

(PHP) MP3z - MP3 Search Engine Script

(PHP) Recipez- PHP Recipe Script

(ASP) Stop image hotlinking and downloading. Web image protection is easy with Image Trapper.

Top Rated Scripts

(Javascripts) Javascript Delayed Redirection Rating: 5

(PHP) Random Links and images with PHP & MySQL Rating: 5

(PHP) RSS/XML news feed headline grabber! Rating: 5

(PHP) Random Signatures/Avatars Rating: 5

(Javascripts) Detecting Client Web Browser Rating: 5

© Copyright 2003 - Devscripts.net  Web Analytics