Quote Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Thanatos`
Forum Newbie
Posts: 3
Joined: Fri May 21, 2004 11:18 am
Contact:

Quote Script

Post by Thanatos` »

I'm trying to make a script that reads a quote from a file, then overlays it onto an image. The script is a php file which acts as a png, located here. First, the file wasn't displaying as an image, but as text, but I seem to have fixed the image part, but now I'm getting an error on line 16.. here's the code

Code: Select all

<?php
header('Content-type: image/x-png');
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Expires: Thu, 19 Nov 2099 08:52:00 GMT');
header('Pragma: no-cache');

//define the font settings
$font_file = $_SERVER[DOCUMENT_ROOT]."/sig/CRILLEE.TTF";
$font_size = 10;
$y_start = 58;
$angle = 0;
$max_width = 360;

//read a quote from the text file
$quote_array = file("sig.txt");
$rand((double) microtime() * 10000000);
$quote = $quote_array[array_rand($quote_array)];

//calc horizontal starting point
$line_width = imagettfbbox($font_size, $angle, $font_file, $quote_array[$quote]);
$x_start = (($max_width - $line_width[2] - $line_width[0]) / 2) + 12;

//create the image
//header("Content-type: image/png")
$image = imagecreatefrompng("background.png");
$red = imagecolorallocate($image, 245, 245, 245);

//write the text to the image
imagettftext($image, $font_size, $angle, $x_start, $y_start, $red, $font_file, $quote_array[$quote]);

// Create and then destroy the image
imagepng($image);
imagedestroy($image);
?>
?>
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

Line 16 being what?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$rand((double) microtime() * 10000000);

uh.. yeah.. that'd be an error.
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

Heh.. yeah :)
Thanatos`
Forum Newbie
Posts: 3
Joined: Fri May 21, 2004 11:18 am
Contact:

Post by Thanatos` »

I was sort of hoping you'd reply telling me how to fix the error, not simply state that there was an error :P
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

Well I've no idea what that $rand line is supposed to be doing :) It looks like it might be trying to seed the random number generator.. but, who knows. Comment it out.
Thanatos`
Forum Newbie
Posts: 3
Joined: Fri May 21, 2004 11:18 am
Contact:

Post by Thanatos` »

I followed the tutorial from Here. Turns out I'd used a $ instead of an S :P. The sig works, which is good, but the quotes aren't displaying now :(
litebearer
Forum Contributor
Posts: 194
Joined: Sat Mar 27, 2004 5:54 am

Post by litebearer »

well a rough fix would be to create a 1 celled table, display the image as a background for the table/cell and then simply enter the quote as the cell contents. (kind of ridiculous but it would work)
Post Reply