Jump to content

ImageTTFText() failure


ThePhoenixRising
 Share

Recommended Posts

I'm writing a Dynamic image, that display's a user's Name, but for some reason, the kills stat won't print. I made a .php file using the same parsing method, but using echo, and it worked fine. I also know it's not an issue with X,Y, Size, float, anything like that because I tried replacing "$kill" with "Test," and it printed fine.

Here is the actual image:

 

dynfo_rajsig.jpg?cmid=563853

 

And here is the code for it:

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

// get CMID variable from the url
$cmid = $_GET['cmid'];

// create the image using your own background
$image = imagecreatefromjpeg("background.jpg");

// dimensions of the image used
$img_width = 600;
$img_height = 9;

// set the colours
$cool  = imagecolorallocate($image, 81, 86, 96);
$black = imagecolorallocate($image, 0, 0, 0);
$white = imagecolorallocate($image, 255, 255, 255);
$red   = imagecolorallocate($image, 255, 0, 0);
$grey  = imagecolorallocate($image, 204, 204, 204);
$green = imagecolorallocate($image, 206, 129, 18);
$blue  = imagecolorallocate($image, 0, 0, 255);
$yellow  = imagecolorallocate($image, 225, 225, 0);

// set the font and print text
$font = 'Verdana.ttf';

/*
// counter - CHMOD your counter file to 777
$viewss = file("views.txt");
$views = $viewss[0]; $views++;
$fp = fopen("views.txt", "w");
fwrite($fp, $views);
fclose($fp);
$counter = "$views";

// View Output
imagettftext($image, 7, 0, 16, 117, $yellow, $font, "Views:$counter");
*/

// Attempt to make web content grabber.

function get_url_contents($url){
        $crl = curl_init();
        $timeout = 5;
        curl_setopt ($crl, CURLOPT_URL,$url);
        curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
        $ret = curl_exec($crl);
        curl_close($crl);
        return $ret;
}

// Web content grabber execution.
$returned_content = get_url_contents('http://uberstrike.cmune.com/Profile?cmid=' .  $cmid);

// Parsing the returned content for Clan Tag.
$namestart = strpos($returned_content, '<span style="color: #FEC42C; font-size: 20px; font-weight: bold;">');
$nameend = strpos($returned_content, '</span>', $namestart);
$name = substr($returned_content, $namestart, $nameend-$namestart);

// Stripping the parsed Clan Tag of HTML elements.
$name = html_entity_decode(strip_tags($name));

// Clan and name output.
imagettftext($image, 7, 0, 53, 7, $yellow, $font, "$name");

// Parsing the returned content for Global Rank.

$rankstart = strpos($returned_content, '<h2 style="font-size:14px; font-weight:bold; text-indent:0px; margin-left:25px;">');
$rankend = strpos($returned_content, '<br />', $rankstart);
$rank = substr($returned_content, $rankstart, $rankend-$rankstart);

// Stripping the parsed Global Rank of HTML.

$rank = html_entity_decode(strip_tags($rank));

// Filtering Rank to only show the value number, not text or formatting in between.

$rank = str_replace ("G", "", $rank);
$rank = str_replace ("l", "", $rank);
$rank = str_replace ("o", "", $rank);
$rank = str_replace ("b", "", $rank);
$rank = str_replace ("a", "", $rank);
$rank = str_replace ("R", "", $rank);
$rank = str_replace ("n", "", $rank);
$rank = str_replace ("k", "", $rank);
$rank = str_replace (":", "", $rank);
$rank = str_replace (" ", "", $rank);

// Rank Output.

imagettftext($image, 7, 0, 220, 7, $yellow, $font, "$rank");

$killstart = strpos($returned_content, '<h3 style="color: #FEC42C;">All time record</h3>');
$killend = strpos($returned_content, '</tr>', $killstart);
$kill = substr($returned_content, $killstart, $killend-$killstart);

// Stripping the parsed kill of HTML.

$kill = html_entity_decode(strip_tags($kill));

// Filtering kill to only show the value number, not text or formatting in between.

$kill = str_replace ("K", "", $kill);
$kill = str_replace ("i", "", $kill);
$kill = str_replace ("l", "", $kill);
$kill = str_replace ("A", "", $kill);
$kill = str_replace ("t", "", $kill);
$kill = str_replace ("m", "", $kill);
$kill = str_replace ("e", "", $kill);
$kill = str_replace ("r", "", $kill);
$kill = str_replace ("o", "", $kill);
$kill = str_replace ("d", "", $kill);
$kill = str_replace ("c", "", $kill);
$kill = str_replace ("s", "", $kill);
$kill = str_replace (" ", "", $kill);

// Kill Stats output.
imagettftext($image, 7, 0, 410, 7, $yellow, $font, "$kill"); 

// IP Logger
$logfile= 'iplog.html';
$IPlog = $_SERVER['REMOTE_ADDR'];
$logdetails=  date("F j, Y, g:i a") . ': ' . '<a href=http://www.ip2location.com/demo.aspx?ip='.$_SERVER['REMOTE_ADDR'].'>'.$_SERVER['REMOTE_ADDR'].'</a>';
$fplog = fopen($logfile, "a"); 
fwrite($fplog, $logdetails);
fwrite($fplog, "<br>");
fclose($fplog); 

// output and destroy
imagepng($image);
imagedestroy($image);

?>

 

I tried using the same parsing code for the $kill stat, and it works fine: http://dynfosig.com/Phoenix_uploads/clangadget/Test.php?cmid=563853

<?php
// get CMID variable from the url
$cmid = $_GET['cmid'];

function get_url_contents($url){
        $crl = curl_init();
        $timeout = 5;
        curl_setopt ($crl, CURLOPT_URL,$url);
        curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
        $ret = curl_exec($crl);
        curl_close($crl);
        return $ret;
}

$returned_content = get_url_contents('http://uberstrike.cmune.com/Profile?cmid=' .  $cmid);

$killstart = strpos($returned_content, '<h3 style="color: #FEC42C;">All time record</h3>');
$killend = strpos($returned_content, '</tr>', $killstart);
$kill = substr($returned_content, $killstart, $killend-$killstart);

// Stripping the parsed kill of HTML.

$kill = html_entity_decode(strip_tags($kill));

// Filtering kill to only show the value number, not text or formatting in between.

$kill = str_replace ("K", "", $kill);
$kill = str_replace ("i", "", $kill);
$kill = str_replace ("l", "", $kill);
$kill = str_replace ("A", "", $kill);
$kill = str_replace ("t", "", $kill);
$kill = str_replace ("m", "", $kill);
$kill = str_replace ("e", "", $kill);
$kill = str_replace ("r", "", $kill);
$kill = str_replace ("o", "", $kill);
$kill = str_replace ("d", "", $kill);
$kill = str_replace ("c", "", $kill);
$kill = str_replace ("s", "", $kill);
$kill = str_replace (" ", "", $kill);

// Kill Stats output.

echo $kill;

?>

 

* Moderator Note: Please do not remove code snippets from the question.

Link to comment
Share on other sites

The value of $kill has a whole bunch of whitespace around the number. When this gets written with imagettftext(), it is being written but the text falls off the bottom of the image. So before you try to write it to the image, have $kill = trim($kill);.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.