I have a dynamic image that picks out data from a dynamically created .line file.
showimage.php(5)
Expand|Select|Wrap|Line Numbers
- <?php
- include("linesfile.php5");
- $linesDataFile = new DataFile("data.line");
- //$image = ImageCreate(660,240); // 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 = 63; // This stores how far down the image the current line will print
- $cur_line_x = 24; // This stores how far across 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 = 12; // 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 = $pagelinelimit;
- for($i=0;$i<$numberOfLines;$i++) {
- $data = $linesDataFile->getReverseIterate();
- if (count($data)==0) continue;
- $name = "[" . $data[0] . "] ";
- $color = $data[1];
- $font = $data[2];
- $line = $data[3];
- $line = $name . $line;
- //ImageString($image, 2, $cur_line_x, $cur_line_y, trim($line), getColor($color));
- imagettftext($image,10,0,$cur_line_x,$cur_line_y,getColor($color),getfont($font),trim($line));
- $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, 205);
- case "red" :
- return ImageColorAllocate($image, 255, 0, 0);
- case "yellow" :
- return ImageColorAllocate($image, 255, 255, 0);
- case "green" :
- return ImageColorAllocate($image, 0, 255, 0);
- case "orange" :
- return ImageColorAllocate($image, 255, 127, 36);
- case "aqua" :
- return ImageColorAllocate($image, 0, 255, 255);
- default:
- return ImageColorAllocate($image, 255, 255, 255);
- }
- }
- function getfont($font) {
- global $image;
- global $font;
- switch($font) {
- case "fixedsys" :
- return "fixedsys.ttf";
- case "Courbd" :
- return "courbd.ttf";
- case "arial" :
- return "arialbd.ttf";
- case "timesnr" :
- return "timesbd.ttf";
- case "calibri" :
- return "calibrib.ttf";
- case "comicsans" :
- return "comicsans.ttf";
- case "palab" :
- return "palab.ttf";
- default:
- return "courbd.ttf";
- }
- }
- header("Content-Type: image/png"); // tell the browser what we're gonna give it
- ImagePng($image); // paint the image in browser
- ImagePng($image, "./chatbox.png"); //export as png file
- ImageDestroy($image); // clean up resources
- ?>
Expand|Select|Wrap|Line Numbers
- <?php
- include("linesfile.php5");
- $filename = "data.line";
- set_magic_quotes_runtime(0);
- if ($_POST['submit']) {
- // grab the inputted text
- $text = stripcslashes($_POST['input'] . "\n");
- $username = stripslashes($_POST['username']);
- $color = $_POST['color'];
- $font = $_POST['font'];
- $ip = $_SERVER['REMOTE_ADDR'] . "\n";
- $_SESSION['username'] = $username;
- $_SESSION['color'] = $color;
- $dirty = array('many', 'bad', 'words', 'in', 'here'); // I took out the real array just to keep the thread 'clean'.
- foreach($dirty AS $bad_word){
- $text = preg_replace("/$bad_word/i","****", $text);
- }
- $data[] ="\n".$username;
- $data[] =trim($color);
- $data[] =trim($font);
- $data[] =trim($text);
- $datafile = new DataFile($filename);
- if(!$datafile->writeNewLine($data)) die("Error writing to file");
- }
- ?>
To do this I believe I will use Imagecopymerge(). but how would I go about getting the X & Y co-ords for the text that needs changing, in this case '=D'? Baring in mind that everytime a new post is submitted the previous line is moved down.
How would I do this?
Thanks,
Sam
myChatbox - the site, just so you get a feel for the image and input