helraizer Posted October 9, 2007 Share Posted October 9, 2007 ChatBox I created the whole thing again (sort of) creating a .line file, instead of .txt and again loaded it into a dynamic image, so you can choose the colour, and it works =D However I have come across a bug (will explain soon). The showimage.php page is as follows: <?php include("linesfile.php"); $linesDataFile = new DataFile("data.line"); //$image = ImageCreate(550,200); // create the image canvas $image = ImageCreateFromPNG("background.png"); $blue = ImageColorAllocate($image, 200, 200, 255); // prepare some blueness $black = ImageColorAllocate($image, 0, 0, 0); // ... and whiteness $cur_line_y = 45; // This stores how far down the image the current line will print $pagecharwidth = 75; // this is the maximum length of the line before it wraps; $lineheight = 15; // This is how much to move down to print the next line $pagelinelimit = 10; // This is the maximum number lines of text that can be displayed ImageFill($image, 0, 0, $blue); // fill the canvas //ImageString($image, 3, 15, $cur_line_y, trim(stripslashes($wordwrapped[0])), $black); $numberOfLines = $linesDataFile->fileSize(); for($i=0;$i<$numberOfLines;$i++) { $data = $linesDataFile->getNextLine(); $name = "[" . $data[0] . "] "; $color = $data[1]; $line = $data[2]; $line = $name . $line; ImageString($image, 3, 15, $cur_line_y, trim($line), getColor($color)); $cur_line_y += $lineheight; } function getColor($color) { global $image; switch($color) { case "black" : return ImageColorAllocate($image, 0, 0, 0); case "white" : return ImageColorAllocate($image, 255, 255, 255); case "blue" : return ImageColorAllocate($image, 0, 0, 255); case "red" : return ImageColorAllocate($image, 255, 0, 0); case "yellow" : return ImageColorAllocate($image, 255, 255, 0); case "green" : return ImageColorAllocate($image, 0, 255, 0); default: return ImageColorAllocate($image, 255, 255, 255); } } header("Content-Type: image/png"); // tell the browser what we're gonna give it ImagePng($image); // paint the image ImageDestroy($image); // clean up resources ?> The layout of the .line file information is: Username colour message CHATBOXTEXT 3 ben red hi sam ben white hi sam helraizer yellow This is a test of ChatBox The bug is that, when the messages get to the bottom of the image, they carry on going, and just drop off the end. With my last code I could get the last 10 lines, but since the messages that would need to to show in this one are on 3 lines, excluding lines 1 and 2. However, it needs all three lines in order to create the text. The Username and message are shown and the colour in the data.line which determines the colour of the text in the image. How would I get it so that it writes the message on the image and only previews the 'latest' 10 lines, rather than carry on beyond the limits of the image? Hope I was clear there, Thanks, Sam Quote Link to comment https://forums.phpfreaks.com/topic/72460-dynamic-image-help/ Share on other sites More sharing options...
MadTechie Posted October 9, 2007 Share Posted October 9, 2007 did i miss a chapter... i have no idea what your talking about! Quote Link to comment https://forums.phpfreaks.com/topic/72460-dynamic-image-help/#findComment-365391 Share on other sites More sharing options...
helraizer Posted October 9, 2007 Author Share Posted October 9, 2007 did i miss a chapter... i have no idea what your talking about! Ok. I'm talking about creating dynamic images in php. For this one I created a .line file rather than a text file. The raw data from a text file when in placed in a dynamic image can only be black. Where as from the line file it can be any colour you want/define. The way the .line file is set out is as follows. CHATBOXTEXT 3 ben red hi sam ben white hi sam helraizer yellow This is a test of ChatBox /**** File Format Definition: .line Line1: CHATBOXTEXT <- file descriptor Line2: 3 <- the number of lines used for each line to appear in the chatbox Line3 onwards : data for the chatbox Line data format: Line1: the name of the user posting the data Line2: a color available from a specific list Line3: the text to appear in the chatbox */ If I were to pull data straight from a text file, each piece of data for the chatbox would be on 1 line. Which means I could create an array to only show the last 10 lines. However, with this data format, it needs all three lines to create the line in the chatbox image. My question is how do I pull out the information into an array so that it grabs the last 10 entries to the text box, giving it requires the 3 lines (name, colour, message) to create one entry? Hope that cleared something up, Thanks, Sam Quote Link to comment https://forums.phpfreaks.com/topic/72460-dynamic-image-help/#findComment-365405 Share on other sites More sharing options...
MadTechie Posted October 9, 2007 Share Posted October 9, 2007 so you want to deal with the text file! try this.. maybe (boss hoving) <?php $lines = file('theFile.txt'); $GroupsOf = $lines[1]; unset($lines[0]); unset($lines[1]); $N = 0; $C = 0; $Group = array(); foreach($lines as $line) { if($C >= $GroupsOf) { $N++; $C=0; }else{ $C++; } $Group[$N][] = $line; } echo "<pre>"; print_r($Group); ?> Quote Link to comment https://forums.phpfreaks.com/topic/72460-dynamic-image-help/#findComment-365419 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.