When i run this script it comes up with this error: Code: The image "http://localhost/sig/sigtest.php?charid=504826" cannot be displayed, because it contains errors. How can I get the PNG to come up and put text on it? I can show all the text using echo perfectly on a webpage, and also when I use CreateImage to make a black background and put text on it, but I can't overlay it on a premade background. the slkscr.ttf and images are in the same diectory as the script the images we are trying to overlay look like this: PHP: <?php $CharID = $_GET[charid]; $url = "http://myplanetside.station.sony.com/character.jsp?charId=$CharID&worldId=21"; $url2 = "http://www.planetsidestats.com/?s=characters&worldId=21&charId=$CharID"; $contents = file ($url); $contents2 = file ($url2); $output = false; $section = ""; $date = getdate(); $day = $date[mday]; $month = $date[mon]; $year = $date[year]; if ($day <= 7) { if ($month == 3) { $day = $day + 21; $month = 2; } elseif ($month = 9 | $month = 4 | $month = 6 | $month = 11) { $day = $day + 23; $month = $month - 1; } elseif ($month = 1) { $day = $day + 24; $month = 12; $year = $year - 1; } else { $day = $day + 24; $month = $month - 1; } } else { $day = $day - 7; } if ($day < 10) { $day = "0$day"; } if ($month < 10) { $month = "0$month"; } $date = "$year-$month-$day"; for($line=0;$line<sizeof($contents);$line++) { if (ereg("Command", $contents[$line])) { $output=true; $section = "CR"; } if (($output==true) && ($section == "CR")) { list($a, $cr) = split("</span>", $contents[$line]); $output=false; $section = ""; } if (ereg("Battle", $contents[$line])) { $output=true; $section = "BR"; } if (($output==true) && ($section == "BR")) { list($a, $br) = split("</span>", $contents[$line]); $output=false; $section = ""; } if (ereg("N/A", $contents[$line - 1])) { $output=true; $section = "TK"; } if (($output==true) && ($section == "TK")) { list($a, $tk) = split("<strong>", $contents[$line]); $output=false; $section = ""; } if (ereg("Contributed", $contents[$line])) { $output=true; $section = "Outfit"; } if (($output==true) && ($section == "Outfit")) { //list($outfitinf, $outfitpts) = split(":", $contents[$line]); //list($a, $outfit) = split(" ", $outfiting); list($a, $outfitinf) = split("=21\">", $contents[$line]); list($outfit, $outfitpts) = split("</a>:</span>", $outfitinf); $output=false; $section = ""; } if ((ereg("Characters", $contents[$line])) && (ereg("PlanetSide", $contents[$line]))) { $output=true; $section = "Name"; } if (($output==true) && ($section == "Name")) { list($a, $empname) = split("</span>", $contents[$line]); list($empire,$name) = split(" - ", $empname); $output=false; $section = ""; } if (ereg("Facilities", $contents[$line])) { $output=true; $section = "Hacks"; } if (($output==true) && ($section == "Hacks")) { list($a, $hacks) = split("</span>", $contents[$line]); $output=false; $section = ""; } } for($line=0;$line<sizeof($contents2);$line++) { if (ereg("$date", $contents2[$line - 3])) { $output=true; $section = "LWkills"; } if (($output==true) && ($section == "LWkills")) { list($a, $b) = split(".gif>", $contents2[$line]); list($lwkills, $a) = split("<font", $b); $kiw = $tk - $lwkills; $output=false; $section = ""; } if (ereg("$date", $contents2[$line - 4])) { $output=true; $section = "LWhacks"; } if (($output==true) && ($section == "LWhacks")) { list($a, $b) = split(".gif>", $contents2[$line]); list($lwhacks, $a) = split("<font", $b); $hiw = $hacks - $lwhacks; $output=false; $section = ""; } if (ereg("$date", $contents2[$line - 5])) { $output=true; $section = "LWop"; } if (($output==true) && ($section == "LWop")) { list($a, $b) = split(".gif>", $contents2[$line]); list($lwop, $a) = split("<font", $b); $opiw = $outfitpts - $lwop; $output=false; $section = ""; } } $kph = round($tk / $hacks, 2); header ("Content-type: image/png"); $font = 'slkscr.ttf'; $image = @ImageCreateFromPNG('tr_bg.png'); $text_colour = ImageColorAllocate($img_handle, 255,255,255); ImageString($image, $font, 10, 10, "$name", $text_colour); ImageString($image, $font, 10, 20, "$outfit", $text_colour); ImageString($image, $font, 10, 40, "BR - $br", $text_colour); ImageString($image, $font, 10, 60, "CR - $cr", $text_colour); ImagePNG($image); ?> PS this is my brothers first ever PHP script
When I tried the code locally I got this error: Code: Warning: Division by zero in C:\Apache\Apache2\htdocs\imagetest.php on line 165 Warning: Cannot modify header information - headers already sent by (output started at C:\Apache\Apache2\htdocs\imagetest.php:165) in C:\Apache\Apache2\htdocs\imagetest.php on line 168 Warning: imagecolorallocate(): supplied argument is not a valid Image resource in C:\Apache\Apache2\htdocs\imagetest.php on line 173 Warning: imagestring(): supplied argument is not a valid Image resource in C:\Apache\Apache2\htdocs\imagetest.php on line 174 Warning: imagestring(): supplied argument is not a valid Image resource in C:\Apache\Apache2\htdocs\imagetest.php on line 175 Warning: imagestring(): supplied argument is not a valid Image resource in C:\Apache\Apache2\htdocs\imagetest.php on line 176 Warning: imagestring(): supplied argument is not a valid Image resource in C:\Apache\Apache2\htdocs\imagetest.php on line 177 Warning: imagepng(): supplied argument is not a valid Image resource in C:\Apache\Apache2\htdocs\imagetest.php on line 179 I have GD2 installed, so I dont know whats the error. Let me spend some time and dig through this. EDIT: Well I got it working, but your text is all screwy. Lemme see if Icant fix that for you.
hey thanks! we havnt positioned the text yet so thats probably why its screwy, can you tell us what you have changed? the Warning: Division by zero in C:\Apache\Apache2\htdocs\imagetest.php on line 165 error is caused because a charid was not put into the address I think e.g. sig.php?charid=504826
You gotta put the full path to the background image first of all. Second of all your text parsing is all screwed to hell and back. I have no idea half of what your trying to do and the other half wont work so your on your own. Also, to get rid of that division by zero error put an @ infront of the round function. I was using ID 398880 to test but... I am lost in it. I cant get the file to pull more than the first 40 lines of the HTML on the page.
The text parsing must be something to do with your server cause it works fine on our server, we managed to make this using the same method as above http://hamish.no-ip.com/sam/ps-stats.php what would you suggest instead to parse the pages? We are working on the GD now, thanks for the tips btw, we can create the image and put text on top of a created background i.e. black but we cant yet place the text on top of another image?
we got it to work followed the tutorials on webmonkey and realised most of the GD script was wrong! anyway here it is: it takes a while to load though any idea how we can get rid of the strange VT thing after the name?